From 403702d6bbdf8d2acb96b2e15bd77ab5ff3363c6 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 17 Oct 2014 16:26:15 +1100 Subject: [PATCH] Handle pauseAll and resumeAll completely in thread now. Avoids a crash (caused by pauseAll trying to pause a sfx that is still in the list of all sfx, but has a delete command already queued up). --- src/audio/sfx_manager.cpp | 35 +++++++++++++++++++++++++++-------- src/audio/sfx_manager.hpp | 6 +++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 81370c94b..3cf632c17 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -233,7 +233,7 @@ void SFXManager::update(float dt) */ void SFXManager::stopThread() { - queue(SFX_EXIT, NULL); + queue(SFX_EXIT); // Make sure the thread wakes up. pthread_cond_signal(&m_cond_request); } // stopThread @@ -291,7 +291,9 @@ void* SFXManager::mainLoop(void *obj) case SFX_DELETE: { me->deleteSFX(current->m_sfx); break; } - case SFX_LISTENER: me->reallyPositionListenerNow(); break; + case SFX_PAUSE_ALL: me->reallyPauseAllNow(); break; + case SFX_RESUME_ALL: me->reallyResumeAllNow(); break; + case SFX_LISTENER: me->reallyPositionListenerNow(); break; case SFX_UPDATE_MUSIC: music_manager->update( current->m_parameter.getX()); break; default: assert("Not yet supported."); @@ -610,24 +612,41 @@ void SFXManager::deleteSFX(SFXBase *sfx) //---------------------------------------------------------------------------- /** Pauses all looping SFXs. Non-looping SFX will be finished, since it's * otherwise not possible to determine which SFX must be resumed (i.e. were - * actually playing at the time pause was called. + * actually playing at the time pause was called). */ void SFXManager::pauseAll() +{ + queue(SFX_PAUSE_ALL); +} // pauseAll + +//---------------------------------------------------------------------------- +/** Pauses all looping SFXs. Non-looping SFX will be finished, since it's + * otherwise not possible to determine which SFX must be resumed (i.e. were + * actually playing at the time pause was called. + */ +void SFXManager::reallyPauseAllNow() { m_all_sfx.lock(); for (std::vector::iterator i= m_all_sfx.getData().begin(); i!=m_all_sfx.getData().end(); i++) { - (*i)->pause(); + (*i)->reallyPauseNow(); } // for i in m_all_sfx m_all_sfx.unlock(); } // pauseAll //---------------------------------------------------------------------------- -/** - * Resumes all paused SFXs. If sound is disabled, does nothing. +/** Resumes all paused SFXs. If sound is disabled, does nothing. */ void SFXManager::resumeAll() +{ + queue(SFX_RESUME_ALL); +} // resumeAll + +//---------------------------------------------------------------------------- +/** Resumes all paused SFXs. If sound is disabled, does nothing. + */ +void SFXManager::reallyResumeAllNow() { // ignore unpausing if sound is disabled if (!sfxAllowed()) return; @@ -636,7 +655,7 @@ void SFXManager::resumeAll() for (std::vector::iterator i =m_all_sfx.getData().begin(); i!=m_all_sfx.getData().end(); i++) { - (*i)->resume(); + (*i)->reallyResumeNow(); } // for i in m_all_sfx m_all_sfx.unlock(); } // resumeAll @@ -729,7 +748,7 @@ void SFXManager::positionListener(const Vec3 &position, const Vec3 &front, m_listener_front = front; m_listener_up = up; m_listener_position.unlock(); - queue(SFX_LISTENER, NULL); + queue(SFX_LISTENER); } // positionListener //----------------------------------------------------------------------------- diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index aa9d918ff..09ba8ba42 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -65,7 +65,9 @@ public: SFX_PLAY = 1, SFX_STOP, SFX_PAUSE, + SFX_PAUSE_ALL, SFX_RESUME, + SFX_RESUME_ALL, SFX_DELETE, SFX_SPEED, SFX_POSITION, @@ -181,7 +183,7 @@ private: public: static void create(); static void destroy(); - void queue(SFXCommands command, SFXBase *sfx); + void queue(SFXCommands command, SFXBase *sfx=NULL); void queue(SFXCommands command, SFXBase *sfx, float f); void queue(SFXCommands command, SFXBase *sfx, const Vec3 &p); // ------------------------------------------------------------------------ @@ -214,7 +216,9 @@ public: void deleteSFXMapping(const std::string &name); void pauseAll(); + void reallyPauseAllNow(); void resumeAll(); + void reallyResumeAllNow(); void update(float dt); bool soundExist(const std::string &name); void setMasterSFXVolume(float gain);