From 5ad35cc6c6e74b85ea625324fd5935448156e164 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 10 Dec 2006 07:12:20 +0000 Subject: [PATCH] add a failsafe; this runs in a high-priority thread --- stepmania/src/RageSound.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 0b8264d3f3..82bdca7a1b 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -288,7 +288,12 @@ int RageSound::GetData( char *pBuffer, int iFrames ) fRate = m_pSource->GetStreamToSourceRatio(); int iNewSourceFrame = m_pSource->GetNextSourceFrame(); - while( iGotFrames == 0 ) + + /* m_pSource->Read() may return 0, which means "try again immediately". As + * a failsafe, only try this a finite number of times. Use a high number, + * because in principle each filter in the stack may cause this. */ + int iTries = 100; + while( iGotFrames == 0 && --iTries ) { iGotFrames = m_pSource->Read( pBuffer, iFrames ); if( iGotFrames == RageSoundReader::ERROR ) @@ -308,6 +313,14 @@ int RageSound::GetData( char *pBuffer, int iFrames ) ASSERT_M( iGotFrames >= 0, ssprintf("%i", iGotFrames) ); // unhandled error condition } + if( iTries == 0 ) + { + Fail( "Read() busy looping" ); + + /* Pretend we got EOF. */ + return 0; + } + /* If we didn't get any data, don't update iSourceFrame, so we just keep * extrapolating if we're in M_CONTINUE. */ if( iGotFrames == 0 )