From 1f76af4df2d5081b2907e874b8d0d0cba755403b Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 25 Apr 2005 07:02:33 +0000 Subject: [PATCH] tracking down assert on SPlayerOptions --- stepmania/src/OptionRow.cpp | 12 ------------ stepmania/src/OptionRowHandler.cpp | 29 +++++++++++++++++------------ stepmania/src/OptionRowHandler.h | 12 ++++++++++++ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/stepmania/src/OptionRow.cpp b/stepmania/src/OptionRow.cpp index a3b9bf87fa..b54b590792 100644 --- a/stepmania/src/OptionRow.cpp +++ b/stepmania/src/OptionRow.cpp @@ -776,18 +776,6 @@ void OptionRow::HandleMessage( const CString& sMessage ) #define INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( vbSelected ) \ if( GetFirstItemGoesDown() ) \ vbSelected.insert( vbSelected.begin(), false ); -static void VerifySelected( SelectType st, const vector &vbSelected, const CString &sName ) -{ - int iNumSelected = 0; - if( st == SELECT_ONE ) - { - ASSERT_M( vbSelected.size() > 0, ssprintf("%s: %i/%i", sName.c_str(), iNumSelected, int(vbSelected.size())) ); - for( unsigned e = 0; e < vbSelected.size(); ++e ) - if( vbSelected[e] ) - iNumSelected++; - ASSERT_M( iNumSelected == 1, ssprintf("%s: %i/%i", sName.c_str(), iNumSelected, int(vbSelected.size())) ); - } -} void OptionRow::ImportOptions( const vector &vpns ) { diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index 6c33a6f722..8747a334de 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -26,6 +26,7 @@ static void SelectExactlyOne( int iSelection, vector &vbSelectedOut ) { + ASSERT_M( iSelection >= 0 && iSelection < vbSelectedOut.size(), ssprintf("%d/%u",iSelection,vbSelectedOut.size()) ); for( int i=0; i<(int)vbSelectedOut.size(); i++ ) vbSelectedOut[i] = i==iSelection; } @@ -153,8 +154,8 @@ public: } void ImportOption( const OptionRowDefinition &def, const vector &vpns, vector vbSelectedOut[NUM_PLAYERS] ) const { - int FallbackOption = -1; - bool UseFallbackOption = true; + int iFallbackOption = -1; + bool bUseFallbackOption = true; FOREACH_CONST( PlayerNumber, vpns, pn ) { @@ -170,10 +171,10 @@ public: if( mc.IsZero() ) { /* The entry has no effect. This is usually a default "none of the - * above" entry. It will always return true for DescribesCurrentMode(). - * It's only the selected choice if nothing else matches. */ + * above" entry. It will always return true for DescribesCurrentMode(). + * It's only the selected choice if nothing else matches. */ if( def.selectType != SELECT_MULTIPLE ) - FallbackOption = e; + iFallbackOption = e; continue; } @@ -181,7 +182,7 @@ public: { if( mc.DescribesCurrentModeForAllPlayers() ) { - UseFallbackOption = false; + bUseFallbackOption = false; if( def.selectType != SELECT_MULTIPLE ) SelectExactlyOne( e, vbSelOut ); else @@ -192,7 +193,7 @@ public: { if( mc.DescribesCurrentMode( p) ) { - UseFallbackOption = false; + bUseFallbackOption = false; if( def.selectType != SELECT_MULTIPLE ) SelectExactlyOne( e, vbSelOut ); else @@ -201,16 +202,20 @@ public: } } - if( def.selectType == SELECT_ONE && UseFallbackOption ) + if( def.selectType == SELECT_ONE && bUseFallbackOption ) { - if( FallbackOption == -1 ) + if( iFallbackOption == -1 ) { - LOG->Warn( "No options in row \"%s\" were selected, and no fallback row found; selected entry 0", m_sName.c_str() ); - FallbackOption = 0; + CString s = ssprintf("No options in row \"%s\" were selected, and no fallback row found; selected entry 0", m_sName.c_str()); + LOG->Warn( s ); + CHECKPOINT_M( s ); + iFallbackOption = 0; } - SelectExactlyOne( FallbackOption, vbSelOut ); + SelectExactlyOne( iFallbackOption, vbSelOut ); } + + VerifySelected( def.selectType, vbSelOut, def.name ); } } diff --git a/stepmania/src/OptionRowHandler.h b/stepmania/src/OptionRowHandler.h index aebe1e1129..5bbb193518 100644 --- a/stepmania/src/OptionRowHandler.h +++ b/stepmania/src/OptionRowHandler.h @@ -37,6 +37,18 @@ namespace OptionRowHandlerUtil OptionRowHandler* Make( const Command &cmd, OptionRowDefinition &defOut ); } +inline void VerifySelected( SelectType st, const vector &vbSelected, const CString &sName ) +{ + int iNumSelected = 0; + if( st == SELECT_ONE ) + { + ASSERT_M( vbSelected.size() > 0, ssprintf("%s: %i/%i", sName.c_str(), iNumSelected, int(vbSelected.size())) ); + for( unsigned e = 0; e < vbSelected.size(); ++e ) + if( vbSelected[e] ) + iNumSelected++; + ASSERT_M( iNumSelected == 1, ssprintf("%s: %i/%i", sName.c_str(), iNumSelected, int(vbSelected.size())) ); + } +} #endif