diff --git a/stepmania/src/RageSoundManager.cpp b/stepmania/src/RageSoundManager.cpp index ca96485d41..88b2bfb3d2 100644 --- a/stepmania/src/RageSoundManager.cpp +++ b/stepmania/src/RageSoundManager.cpp @@ -161,7 +161,9 @@ void RageSoundManager::CommitPlayingPosition( int ID, int64_t frameno, int pos, RageSound *RageSoundManager::GetSoundByID( int ID ) { - LockMut(g_SoundManMutex); /* lock for access to all_sounds */ + /* You must lock this mutex before calling this function. If you don't, + * from any thread, the returned sound may be invalidated. */ + ASSERT( g_SoundManMutex.IsLockedByThisThread() ); /* Find the sound with p.ID. */ set::iterator it; @@ -174,6 +176,10 @@ RageSound *RageSoundManager::GetSoundByID( int ID ) /* This is only called by RageSoundManager::Update. */ void RageSoundManager::FlushPosMapQueue() { + /* Lock, to make sure sounds returned by GetSoundByID remain valid until we're + * done with them. */ + LockMut(g_SoundManMutex); + queued_pos_map_t p; /* We don't need to lock to access pos_map_queue. */