diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 2710fe9b94..01f43c8325 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -608,7 +608,9 @@ void RageSound::StopPlaying() /* 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. */ + SOUNDMAN->UnregisterSound( this ); ID = SOUNDMAN->GetUniqueID(); + SOUNDMAN->RegisterSound( this ); // LOG->Trace("StopPlaying %p finished (%s)", this, this->GetLoadedFilePath().c_str()); diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index 04a25e1cf7..3a5a8692e5 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -97,7 +97,7 @@ void RageSoundManager::Update(float delta) FlushPosMapQueue(); /* Scan the owned_sounds list for sounds that are no longer playing, and delete them. */ - g_SoundManMutex.Lock(); /* lock for access to all_sounds */ + g_SoundManMutex.Lock(); /* lock for access to owned_sounds */ set ToDelete; for( set::iterator it = owned_sounds.begin(); it != owned_sounds.end(); ++it ) { @@ -110,7 +110,7 @@ void RageSoundManager::Update(float delta) for( set::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it ) owned_sounds.erase( *it ); - g_SoundManMutex.Unlock(); /* finished with owned_sounds and all_sounds */ + g_SoundManMutex.Unlock(); /* finished with owned_sounds */ /* Be sure to release g_SoundManMutex before deleting sounds. */ for( set::iterator it = ToDelete.begin(); it != ToDelete.end(); ++it ) @@ -124,14 +124,14 @@ void RageSoundManager::Update(float delta) void RageSoundManager::RegisterSound( RageSound *p ) { g_SoundManMutex.Lock(); /* lock for access to all_sounds */ - all_sounds.insert( p ); + all_sounds[p->GetID()] = p; g_SoundManMutex.Unlock(); /* finished with all_sounds */ } void RageSoundManager::UnregisterSound( RageSound *p ) { g_SoundManMutex.Lock(); /* lock for access to all_sounds */ - all_sounds.erase( p ); + all_sounds.erase( p->GetID() ); g_SoundManMutex.Unlock(); /* finished with all_sounds */ } @@ -160,11 +160,11 @@ RageSound *RageSoundManager::GetSoundByID( int ID ) LockMut( g_SoundManMutex ); /* Find the sound with p.ID. */ - set::iterator it; - for( it = all_sounds.begin(); it != all_sounds.end(); ++it ) - if( (*it)->GetID() == ID ) - return *it; - return NULL; + map::iterator it; + it = all_sounds.find( ID ); + if( it == all_sounds.end() ) + return NULL; + return it->second; } /* This is only called by RageSoundManager::Update. */ diff --git a/stepmania/src/RageSoundManager.h b/stepmania/src/RageSoundManager.h index 466d967865..3abe7e5a08 100644 --- a/stepmania/src/RageSoundManager.h +++ b/stepmania/src/RageSoundManager.h @@ -16,8 +16,8 @@ class RageSoundManager * when they're finished playing): */ set owned_sounds; - /* A list of all sounds that currently exist. */ - set all_sounds; + /* A list of all sounds that currently exist, by ID. */ + map all_sounds; RageSoundDriver *driver;