From 5bc199c9b7fcf90111c46e397a68b853d004ba44 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Wed, 18 Aug 2010 14:12:10 -0500 Subject: [PATCH] Improve out of bounds setstate error message. [shakesoda] --- src/Sprite.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Sprite.cpp b/src/Sprite.cpp index 7f01cd4212..02c2155823 100644 --- a/src/Sprite.cpp +++ b/src/Sprite.cpp @@ -706,10 +706,12 @@ int Sprite::GetNumStates() const 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 - // problems in debug builds, but they're not fatal. - // + /* + * 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 + * problems in debug builds, but they're not fatal. + */ + // Never warn about setting state 0. if( iNewState != 0 && (iNewState < 0 || iNewState >= (int)m_States.size()) ) { @@ -719,8 +721,13 @@ void Sprite::SetState( int iNewState ) { RString sError; if( m_pTexture ) - sError = ssprintf("A Sprite '%s' (\"%s\") tried to set state index %d, but it has only %u states.", - m_pTexture->GetID().filename.c_str(), this->m_sName.c_str(), iNewState, unsigned(m_States.size())); + sError = ssprintf("A Sprite '%s' (\"%s\") tried to set state to frame %d, but it has only %u frames.", + /* + * 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 sError = ssprintf("A Sprite (\"%s\") tried to set state index %d, but no texture is loaded.", this->m_sName.c_str(), iNewState );