BGE fix: ignore sounds that cannot be opened instead of crashing. ;-)
authorJoerg Mueller <nexyon@gmail.com>
Tue, 6 Sep 2011 21:02:26 +0000 (21:02 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Tue, 6 Sep 2011 21:02:26 +0000 (21:02 +0000)
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Ketsji/KX_SoundActuator.cpp

index 8fc224f..6ba178c 100644 (file)
@@ -413,14 +413,21 @@ void BL_ConvertActuators(char* maggiename,
                                                // if sound shall be 3D but isn't mono, we have to make it mono!
                                                if(is3d)
                                                {
-                                                       AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
-                                                       if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
+                                                       try
                                                        {
-                                                               AUD_DeviceSpecs specs;
-                                                               specs.channels = AUD_CHANNELS_MONO;
-                                                               specs.rate = AUD_RATE_INVALID;
-                                                               specs.format = AUD_FORMAT_INVALID;
-                                                               snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
+                                                               AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
+                                                               if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
+                                                               {
+                                                                       AUD_DeviceSpecs specs;
+                                                                       specs.channels = AUD_CHANNELS_MONO;
+                                                                       specs.rate = AUD_RATE_INVALID;
+                                                                       specs.format = AUD_FORMAT_INVALID;
+                                                                       snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
+                                                               }
+                                                       }
+                                                       catch(AUD_Exception&)
+                                                       {
+                                                               // sound cannot be played... ignore
                                                        }
                                                }
                                        }
index 6c7b515..f24243f 100644 (file)
@@ -108,7 +108,15 @@ void KX_SoundActuator::play()
                break;
        }
 
-       m_handle = AUD_getDevice()->play(sound, 0);
+       try
+       {
+               m_handle = AUD_getDevice()->play(sound, 0);
+       }
+       catch(AUD_Exception&)
+       {
+               // cannot play back, ignore
+               return;
+       }
 
        AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(m_handle);