Improve out of bounds setstate error message. [shakesoda]

This commit is contained in:
AJ Kelly
2010-08-18 14:12:10 -05:00
parent f4a6c11160
commit 5bc199c9b7
+13 -6
View File
@@ -706,10 +706,12 @@ int Sprite::GetNumStates() const
void Sprite::SetState( int iNewState ) void Sprite::SetState( int iNewState )
{ {
// This assert will likely trigger if the "missing" theme element graphic /*
// is loaded in place of a multi-frame sprite. We want to know about these * This assert will likely trigger if the "missing" theme element graphic
// problems in debug builds, but they're not fatal. * is loaded in place of a multi-frame sprite. We want to know about these
// * problems in debug builds, but they're not fatal.
*/
// Never warn about setting state 0. // Never warn about setting state 0.
if( iNewState != 0 && (iNewState < 0 || iNewState >= (int)m_States.size()) ) if( iNewState != 0 && (iNewState < 0 || iNewState >= (int)m_States.size()) )
{ {
@@ -719,8 +721,13 @@ void Sprite::SetState( int iNewState )
{ {
RString sError; RString sError;
if( m_pTexture ) if( m_pTexture )
sError = ssprintf("A Sprite '%s' (\"%s\") tried to set state index %d, but it has only %u states.", sError = ssprintf("A Sprite '%s' (\"%s\") tried to set state to frame %d, but it has only %u frames.",
m_pTexture->GetID().filename.c_str(), this->m_sName.c_str(), iNewState, unsigned(m_States.size())); /*
* Using the state directly tends to give you an error message like "tried to set frame 6 of 6"
* which is very confusing if you don't know that one is 0-indexed and the other is 1-indexed.
* - Colby
*/
m_pTexture->GetID().filename.c_str(), this->m_sName.c_str(), iNewState+1, unsigned(m_States.size()));
else else
sError = ssprintf("A Sprite (\"%s\") tried to set state index %d, but no texture is loaded.", sError = ssprintf("A Sprite (\"%s\") tried to set state index %d, but no texture is loaded.",
this->m_sName.c_str(), iNewState ); this->m_sName.c_str(), iNewState );