[Orxonox-commit 3163] r7856 - code/trunk/src/orxonox/sound

landauf at orxonox.net landauf at orxonox.net
Fri Feb 11 16:05:55 CET 2011


Author: landauf
Date: 2011-02-11 16:05:55 +0100 (Fri, 11 Feb 2011)
New Revision: 7856

Modified:
   code/trunk/src/orxonox/sound/AmbientSound.cc
   code/trunk/src/orxonox/sound/AmbientSound.h
   code/trunk/src/orxonox/sound/BaseSound.cc
   code/trunk/src/orxonox/sound/BaseSound.h
   code/trunk/src/orxonox/sound/SoundManager.cc
Log:
fixed (?) an endless loop in SoundManager::preUpdate if a non-looping ambient sound faded out. maybe solved the problem by returning a bool from stop() depending on whether or not the sound source was destroyed.

someone who knows more about the sound system should probably have a look at this.

Modified: code/trunk/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.cc	2011-02-11 13:20:13 UTC (rev 7855)
+++ code/trunk/src/orxonox/sound/AmbientSound.cc	2011-02-11 15:05:55 UTC (rev 7856)
@@ -56,10 +56,11 @@
             SoundManager::getInstance().registerAmbientSound(this);
     }
 
-    void AmbientSound::stop()
+    bool AmbientSound::stop()
     {
         if (GameMode::playsSound())
             SoundManager::getInstance().unregisterAmbientSound(this);
+        return false; // sound source not (yet) destroyed - return false
     }
 
     void AmbientSound::pause()

Modified: code/trunk/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.h	2011-02-11 13:20:13 UTC (rev 7855)
+++ code/trunk/src/orxonox/sound/AmbientSound.h	2011-02-11 15:05:55 UTC (rev 7856)
@@ -50,7 +50,7 @@
         AmbientSound();
 
         void play();
-        void stop();
+        bool stop();
         void pause();
 
         void setAmbientSource(const std::string& source);

Modified: code/trunk/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/BaseSound.cc	2011-02-11 13:20:13 UTC (rev 7855)
+++ code/trunk/src/orxonox/sound/BaseSound.cc	2011-02-11 15:05:55 UTC (rev 7856)
@@ -95,7 +95,7 @@
         }
     }
 
-    void BaseSound::doStop()
+    bool BaseSound::doStop()
     {
         this->state_ = Stopped;
         if (alIsSource(this->audioSource_))
@@ -108,7 +108,10 @@
             // Get a no source ID
             this->audioSource_ += 123455;
             while (alIsSource(++this->audioSource_));
+            
+            return true; // sound source destroyed - return true
         }
+        return false; // nothing done - return false
     }
 
     void BaseSound::doPause()

Modified: code/trunk/src/orxonox/sound/BaseSound.h
===================================================================
--- code/trunk/src/orxonox/sound/BaseSound.h	2011-02-11 13:20:13 UTC (rev 7855)
+++ code/trunk/src/orxonox/sound/BaseSound.h	2011-02-11 15:05:55 UTC (rev 7856)
@@ -50,7 +50,7 @@
         void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
 
         virtual void play()  { this->doPlay(); }
-        virtual void stop()  { this->doStop(); }
+        virtual bool stop()  { return this->doStop(); } // returns true if the sound source was destroyed
         virtual void pause() { this->doPause(); }
 
         bool isPlaying() const { return this->state_ == Playing; }
@@ -85,7 +85,7 @@
         virtual ~BaseSound();
 
         void doPlay();
-        void doStop();
+        bool doStop(); // returns true if the sound source was destroyed
         void doPause();
 
         // network callbacks

Modified: code/trunk/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/trunk/src/orxonox/sound/SoundManager.cc	2011-02-11 13:20:13 UTC (rev 7855)
+++ code/trunk/src/orxonox/sound/SoundManager.cc	2011-02-11 15:05:55 UTC (rev 7856)
@@ -240,8 +240,8 @@
             alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);
             if (state == AL_STOPPED)
             {
-                this->usedSoundSources_[i].second->stop();
-                --i;
+                if (this->usedSoundSources_[i].second->stop()) // if stop() returns true, the sound source was removed, thus decrement the array index
+                    --i;
             }
         }
     }




More information about the Orxonox-commit mailing list