diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index b95eb9914c..86406a9c95 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -72,7 +72,9 @@ RageSound::RageSound(): databuf.reserve(internal_buffer_size); /* Register ourself. */ - ID = SOUNDMAN->RegisterSound( this ); + SOUNDMAN->RegisterSound( this ); + + ID = SOUNDMAN->GetUniqueID(); } RageSound::~RageSound() @@ -98,8 +100,11 @@ RageSound::RageSound(const RageSound &cpy): *this = cpy; - /* Register ourself. We have a different ID than our parent. */ - ID = SOUNDMAN->RegisterSound( this ); + /* Register ourself. */ + SOUNDMAN->RegisterSound( this ); + + /* We have a different ID than our parent. */ + ID = SOUNDMAN->GetUniqueID(); } RageSound &RageSound::operator=( const RageSound &cpy ) @@ -605,6 +610,12 @@ void RageSound::StopPlaying() max_driver_frame = 0; pos_map.Clear(); + + /* We may still have positions queued up in RageSoundManager. We need to make sure + * that we don't accept those; otherwise, if we start playing again quickly, they'll + * confuse GetPositionSeconds(). Do this by changing our ID. */ + ID = SOUNDMAN->GetUniqueID(); + // LOG->Trace("StopPlaying %p finished (%s)", this, this->GetLoadedFilePath().c_str()); m_Mutex.Unlock(); diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 07669cc7ee..fce1d8d504 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -122,14 +122,11 @@ void RageSoundManager::Update(float delta) } /* Register the given sound, and return a unique ID. */ -int RageSoundManager::RegisterSound( RageSound *p ) +void RageSoundManager::RegisterSound( RageSound *p ) { - LockMut(g_SoundManMutex); /* lock for access to all_sounds and iID */ - + g_SoundManMutex.Lock(); /* lock for access to all_sounds */ all_sounds.insert( p ); - - static int iID = 0; - return ++iID; + g_SoundManMutex.Unlock(); /* finished with all_sounds */ } void RageSoundManager::UnregisterSound( RageSound *p ) @@ -139,6 +136,14 @@ void RageSoundManager::UnregisterSound( RageSound *p ) g_SoundManMutex.Unlock(); /* finished with all_sounds */ } +/* Return a unique ID. */ +int RageSoundManager::GetUniqueID() +{ + LockMut(g_SoundManMutex); /* serialize iID */ + static int iID = 0; + return ++iID; +} + void RageSoundManager::RegisterPlayingSound( RageSound *p ) { g_SoundManMutex.Lock(); /* lock for access to playing_sounds */ diff --git a/stepmania/src/RageSoundManager.h b/stepmania/src/RageSoundManager.h index 2e8fe6d805..83b1fcbeb1 100644 --- a/stepmania/src/RageSoundManager.h +++ b/stepmania/src/RageSoundManager.h @@ -44,8 +44,9 @@ public: void StartMixing( RageSoundBase *snd ); /* used by RageSound */ void StopMixing( RageSoundBase *snd ); /* used by RageSound */ int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */ - int RegisterSound( RageSound *p ); /* used by RageSound */ + void RegisterSound( RageSound *p ); /* used by RageSound */ void UnregisterSound( RageSound *p ); /* used by RageSound */ + int GetUniqueID(); /* used by RageSound */ void RegisterPlayingSound( RageSound *p ); /* used by RageSound */ void UnregisterPlayingSound( RageSound *p ); /* used by RageSound */ void CommitPlayingPosition( int ID, int64_t frameno, int pos, int got_bytes ); /* used by drivers */