tracking down assert on SPlayerOptions
This commit is contained in:
@@ -776,18 +776,6 @@ void OptionRow::HandleMessage( const CString& sMessage )
|
|||||||
#define INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( vbSelected ) \
|
#define INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( vbSelected ) \
|
||||||
if( GetFirstItemGoesDown() ) \
|
if( GetFirstItemGoesDown() ) \
|
||||||
vbSelected.insert( vbSelected.begin(), false );
|
vbSelected.insert( vbSelected.begin(), false );
|
||||||
static void VerifySelected( SelectType st, const vector<bool> &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<PlayerNumber> &vpns )
|
void OptionRow::ImportOptions( const vector<PlayerNumber> &vpns )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
static void SelectExactlyOne( int iSelection, vector<bool> &vbSelectedOut )
|
static void SelectExactlyOne( int iSelection, vector<bool> &vbSelectedOut )
|
||||||
{
|
{
|
||||||
|
ASSERT_M( iSelection >= 0 && iSelection < vbSelectedOut.size(), ssprintf("%d/%u",iSelection,vbSelectedOut.size()) );
|
||||||
for( int i=0; i<(int)vbSelectedOut.size(); i++ )
|
for( int i=0; i<(int)vbSelectedOut.size(); i++ )
|
||||||
vbSelectedOut[i] = i==iSelection;
|
vbSelectedOut[i] = i==iSelection;
|
||||||
}
|
}
|
||||||
@@ -153,8 +154,8 @@ public:
|
|||||||
}
|
}
|
||||||
void ImportOption( const OptionRowDefinition &def, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
|
void ImportOption( const OptionRowDefinition &def, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
|
||||||
{
|
{
|
||||||
int FallbackOption = -1;
|
int iFallbackOption = -1;
|
||||||
bool UseFallbackOption = true;
|
bool bUseFallbackOption = true;
|
||||||
|
|
||||||
FOREACH_CONST( PlayerNumber, vpns, pn )
|
FOREACH_CONST( PlayerNumber, vpns, pn )
|
||||||
{
|
{
|
||||||
@@ -170,10 +171,10 @@ public:
|
|||||||
if( mc.IsZero() )
|
if( mc.IsZero() )
|
||||||
{
|
{
|
||||||
/* The entry has no effect. This is usually a default "none of the
|
/* The entry has no effect. This is usually a default "none of the
|
||||||
* above" entry. It will always return true for DescribesCurrentMode().
|
* above" entry. It will always return true for DescribesCurrentMode().
|
||||||
* It's only the selected choice if nothing else matches. */
|
* It's only the selected choice if nothing else matches. */
|
||||||
if( def.selectType != SELECT_MULTIPLE )
|
if( def.selectType != SELECT_MULTIPLE )
|
||||||
FallbackOption = e;
|
iFallbackOption = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +182,7 @@ public:
|
|||||||
{
|
{
|
||||||
if( mc.DescribesCurrentModeForAllPlayers() )
|
if( mc.DescribesCurrentModeForAllPlayers() )
|
||||||
{
|
{
|
||||||
UseFallbackOption = false;
|
bUseFallbackOption = false;
|
||||||
if( def.selectType != SELECT_MULTIPLE )
|
if( def.selectType != SELECT_MULTIPLE )
|
||||||
SelectExactlyOne( e, vbSelOut );
|
SelectExactlyOne( e, vbSelOut );
|
||||||
else
|
else
|
||||||
@@ -192,7 +193,7 @@ public:
|
|||||||
{
|
{
|
||||||
if( mc.DescribesCurrentMode( p) )
|
if( mc.DescribesCurrentMode( p) )
|
||||||
{
|
{
|
||||||
UseFallbackOption = false;
|
bUseFallbackOption = false;
|
||||||
if( def.selectType != SELECT_MULTIPLE )
|
if( def.selectType != SELECT_MULTIPLE )
|
||||||
SelectExactlyOne( e, vbSelOut );
|
SelectExactlyOne( e, vbSelOut );
|
||||||
else
|
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() );
|
CString s = ssprintf("No options in row \"%s\" were selected, and no fallback row found; selected entry 0", m_sName.c_str());
|
||||||
FallbackOption = 0;
|
LOG->Warn( s );
|
||||||
|
CHECKPOINT_M( s );
|
||||||
|
iFallbackOption = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectExactlyOne( FallbackOption, vbSelOut );
|
SelectExactlyOne( iFallbackOption, vbSelOut );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VerifySelected( def.selectType, vbSelOut, def.name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,18 @@ namespace OptionRowHandlerUtil
|
|||||||
OptionRowHandler* Make( const Command &cmd, OptionRowDefinition &defOut );
|
OptionRowHandler* Make( const Command &cmd, OptionRowDefinition &defOut );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void VerifySelected( SelectType st, const vector<bool> &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
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user