From dc25295879a4222794ae9a27971710cc97ccfee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 9 Sep 2019 11:09:52 +0200 Subject: [PATCH 1/3] Catch stoi invalid_argument in BGCHANGES --- src/NotesLoaderSM.cpp | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index 8f2c219912..fa2a6c0279 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -976,9 +976,18 @@ bool SMLoader::LoadFromBGChangesVector( BackgroundChange &change, std::vector Date: Sat, 13 Jun 2020 13:46:02 +0200 Subject: [PATCH 2/3] Extract logic to NoteDataUtil::StringInterpretsAs --- src/NoteDataUtil.cpp | 11 +++++++++++ src/NoteDataUtil.h | 5 +++++ src/NotesLoaderSM.cpp | 46 +++++++------------------------------------ 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/NoteDataUtil.cpp b/src/NoteDataUtil.cpp index 330b3f0b58..ee5e321258 100644 --- a/src/NoteDataUtil.cpp +++ b/src/NoteDataUtil.cpp @@ -11,6 +11,17 @@ #include "TimingData.h" #include +bool NoteDataUtil::StringInterpretsAs( const std::string& str, int integer ) { + try + { + return std::stoi( str ) == integer; + } + catch ( const std::invalid_argument & ) + { + return false; + } +} + // TODO: Remove these constants that aren't time signature-aware static const int BEATS_PER_MEASURE = 4; static const int ROWS_PER_MEASURE = ROWS_PER_BEAT * BEATS_PER_MEASURE; diff --git a/src/NoteDataUtil.h b/src/NoteDataUtil.h index a855ddd2a6..8b9ea53432 100644 --- a/src/NoteDataUtil.h +++ b/src/NoteDataUtil.h @@ -23,6 +23,11 @@ void LightTransformHelper( const NoteData &in, NoteData &out, const vector * and makes it much easier to change NoteData internally in the future. */ namespace NoteDataUtil { + /** + * @brief Whether a string can be interpreted as the provided signed integer + */ + bool StringInterpretsAs( const std::string& str, int integer ); + NoteType GetSmallestNoteTypeForMeasure( const NoteData &nd, int iMeasureIndex ); NoteType GetSmallestNoteTypeInRange( const NoteData &nd, int iStartIndex, int iEndIndex ); void LoadFromSMNoteDataString( NoteData &out, const RString &sSMNoteData, bool bComposite ); diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index fa2a6c0279..b0b52148a2 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -3,6 +3,7 @@ #include "BackgroundUtil.h" #include "GameManager.h" #include "MsdFile.h" +#include "NoteDataUtil.h" #include "NoteTypes.h" #include "RageFileManager.h" #include "RageLog.h" @@ -974,58 +975,25 @@ bool SMLoader::LoadFromBGChangesVector( BackgroundChange &change, std::vector Date: Sat, 13 Jun 2020 15:19:50 +0200 Subject: [PATCH 3/3] Don't disable exceptions on macOS --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f772ae3123..c29df4338d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -247,8 +247,6 @@ elseif(APPLE) "${SM_XCODE_DIR}/plistHelper.hpp" XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/archutils/Darwin/StepMania.pch" - XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS - "NO" XCODE_ATTRIBUTE_LIBRARY_SEARCH_PATHS "${SM_XCODE_DIR}/Libraries")