From d32745bd94ac2bb22fdcb6b033d8eee1cb1af40d Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 15 Feb 2004 21:39:15 +0000 Subject: [PATCH] ThemeManager::GetMetricRaw: check "fallback" recursively chekc for infinite recursion --- stepmania/src/ThemeManager.cpp | 41 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index c3ecd412cc..49c194c655 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -205,22 +205,23 @@ CString ThemeManager::GetThemeDirFromName( const CString &sThemeName ) CString ThemeManager::GetPathToAndFallback( CString sThemeName, ElementCategory category, CString sClassName, CString sElement ) { - // search with requested name - CString sRet = GetPathToRaw( sThemeName, category, sClassName, sElement ); - if( !sRet.empty() ) - return sRet; - - // search fallback name (if any) - // XXX: should this check fallbacks recursively? - CString sFallback; - if( m_pIniMetrics->GetValue(sClassName,"Fallback",sFallback) ) + int n = 100; + while( n-- ) { - sRet = GetPathToAndFallback( sThemeName, category, sFallback, sElement ); + // search with requested name + CString sRet = GetPathToRaw( sThemeName, category, sClassName, sElement ); if( !sRet.empty() ) return sRet; + + // search fallback name (if any) + CString sFallback; + if( !m_pIniMetrics->GetValue(sClassName,"Fallback",sFallback) ) + return ""; + sClassName = sFallback; } - return ""; + RageException::Throw("Infinite recursion looking up theme element from theme \"%s\", class \"%s\"", + sThemeName.c_str(), sClassName.c_str() ); } CString ThemeManager::GetPathToRaw( CString sThemeName, ElementCategory category, CString sClassName, CString sElement ) @@ -490,13 +491,19 @@ void ThemeManager::ReloadMetrics() bool ThemeManager::GetMetricRaw( CString sClassName, CString sValueName, CString &ret ) { - if( m_pIniMetrics->GetValue(sClassName,sValueName,ret) ) - return true; + int n = 100; + while( n-- ) + { + if( m_pIniMetrics->GetValue(sClassName,sValueName,ret) ) + return true; - CString sFallback; - if( m_pIniMetrics->GetValue(sClassName,"Fallback",sFallback) ) - return GetMetricRaw( sFallback, sValueName, ret ); - return false; + CString sFallback; + if( !m_pIniMetrics->GetValue(sClassName,"Fallback",sFallback) ) + return false; + sClassName = sFallback; + } + + RageException::Throw("Infinite recursion looking up theme metric from class \"%s\"", sClassName.c_str() ); } CString ThemeManager::GetMetricRaw( CString sClassName, CString sValueName )