[Orxonox-commit 3162] r7855 - code/trunk/src/orxonox/sound

landauf at orxonox.net landauf at orxonox.net
Fri Feb 11 14:20:14 CET 2011


Author: landauf
Date: 2011-02-11 14:20:13 +0100 (Fri, 11 Feb 2011)
New Revision: 7855

Modified:
   code/trunk/src/orxonox/sound/SoundManager.cc
   code/trunk/src/orxonox/sound/SoundManager.h
Log:
fixed a bug which caused the application to crash if the game was ended while cross-fading ambient sound. in particular AmbientSound registered itself again at SoundManager as soon as SoundManager was deleted. added a bool to prevent this behavior.

Modified: code/trunk/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/trunk/src/orxonox/sound/SoundManager.cc	2011-02-11 12:03:47 UTC (rev 7854)
+++ code/trunk/src/orxonox/sound/SoundManager.cc	2011-02-11 13:20:13 UTC (rev 7855)
@@ -69,6 +69,8 @@
         : effectsPoolSize_(0)
     {
         RegisterRootObject(SoundManager);
+        
+        this->bDestructorCalled_ = false;
 
         // See whether we even want to load
         bool bDisableSound_ = false;
@@ -162,6 +164,7 @@
     SoundManager::~SoundManager()
     {
         // Erase fade lists because of the smart pointers
+        this->bDestructorCalled_ = true;
         this->fadeInList_.clear();
         this->fadeOutList_.clear();
 
@@ -342,7 +345,7 @@
 
     void SoundManager::registerAmbientSound(AmbientSound* newAmbient)
     {
-        if (newAmbient != NULL)
+        if (newAmbient != NULL && !this->bDestructorCalled_)
         {
             for (AmbientList::const_iterator it = this->ambientSounds_.begin(); it != this->ambientSounds_.end(); ++it)
             {
@@ -365,7 +368,7 @@
 
     void SoundManager::unregisterAmbientSound(AmbientSound* oldAmbient)
     {
-        if (oldAmbient == NULL || ambientSounds_.empty())
+        if (oldAmbient == NULL || ambientSounds_.empty() || this->bDestructorCalled_)
             return;
 
         if (this->ambientSounds_.front().first == oldAmbient)

Modified: code/trunk/src/orxonox/sound/SoundManager.h
===================================================================
--- code/trunk/src/orxonox/sound/SoundManager.h	2011-02-11 12:03:47 UTC (rev 7854)
+++ code/trunk/src/orxonox/sound/SoundManager.h	2011-02-11 13:20:13 UTC (rev 7855)
@@ -145,6 +145,8 @@
         unsigned int maxSources_;
         std::vector<ALuint> availableSoundSources_;
         std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_;
+        
+        bool bDestructorCalled_; ///< Becomes true if the destructor is called - used to prevent ambient sounds from registering after the lists were cleared
 
         static SoundManager* singletonPtr_s;
     }; // tolua_export




More information about the Orxonox-commit mailing list