Revision: 16279
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16279
Author:   ben2610
Date:     2008-08-28 10:13:58 +0200 (Thu, 28 Aug 2008)

Log Message:
-----------
BGE patch: fix division by 0 error when sound sample cannot be loaded in sound 
actuator.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp   
2008-08-28 07:03:23 UTC (rev 16278)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp   
2008-08-28 08:13:58 UTC (rev 16279)
@@ -406,50 +406,51 @@
                                        /* Note, allowing actuators for sounds 
that are not there was added since 2.47
                                         * This is because python may expect 
the actuator and raise an exception if it dosnt find it
                                         * better just to add a dummy sound 
actuator. */
-                                       /*if (sampleisloaded)*/
-                                       
-                                       /* setup the SND_SoundObject */
-                                       SND_SoundObject* sndobj = new 
SND_SoundObject();
-                                       sndobj->SetSampleName(samplename.Ptr());
-                                       sndobj->SetObjectName(bact->name);
-                                       if (soundact->sound) {
-                                               
sndobj->SetRollOffFactor(soundact->sound->attenuation);
-                                               
sndobj->SetGain(soundact->sound->volume);
-                                               
sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0)));
-                                               //                              
                        sndobj->SetLoopStart(soundact->sound->loopstart);
-                                               //                              
                        sndobj->SetLoopStart(soundact->sound->loopend);
-                                               if (soundact->sound->flags & 
SOUND_FLAGS_LOOP)
-                                               {
-                                                       if 
(soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
-                                                               
sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
+                                       SND_SoundObject* sndobj = NULL;
+                                       if (sampleisloaded)
+                                       {
+                                               /* setup the SND_SoundObject */
+                                               sndobj = new SND_SoundObject();
+                                               
sndobj->SetSampleName(samplename.Ptr());
+                                               
sndobj->SetObjectName(bact->name);
+                                               if (soundact->sound) {
+                                                       
sndobj->SetRollOffFactor(soundact->sound->attenuation);
+                                                       
sndobj->SetGain(soundact->sound->volume);
+                                                       
sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0)));
+                                                       //                      
                                
sndobj->SetLoopStart(soundact->sound->loopstart);
+                                                       //                      
                                sndobj->SetLoopStart(soundact->sound->loopend);
+                                                       if 
(soundact->sound->flags & SOUND_FLAGS_LOOP)
+                                                       {
+                                                               if 
(soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
+                                                                       
sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
+                                                               else
+                                                                       
sndobj->SetLoopMode(SND_LOOP_NORMAL);
+                                                       }
+                                                       else {
+                                                               
sndobj->SetLoopMode(SND_LOOP_OFF);
+                                                       }
+                                                       
+                                                       if 
(soundact->sound->flags & SOUND_FLAGS_PRIORITY)
+                                                               
sndobj->SetHighPriority(true);
                                                        else
-                                                               
sndobj->SetLoopMode(SND_LOOP_NORMAL);
+                                                               
sndobj->SetHighPriority(false);
+                                                       
+                                                       if 
(soundact->sound->flags & SOUND_FLAGS_3D)
+                                                               
sndobj->Set3D(true);
+                                                       else
+                                                               
sndobj->Set3D(false);
                                                }
                                                else {
+                                                       /* dummy values for a 
NULL sound
+                                                       * see editsound.c - 
defaults are unlikely to change soon */
+                                                       
sndobj->SetRollOffFactor(1.0);
+                                                       sndobj->SetGain(1.0);
+                                                       sndobj->SetPitch(1.0);
                                                        
sndobj->SetLoopMode(SND_LOOP_OFF);
-                                               }
-                                               
-                                               if (soundact->sound->flags & 
SOUND_FLAGS_PRIORITY)
-                                                       
sndobj->SetHighPriority(true);
-                                               else
                                                        
sndobj->SetHighPriority(false);
-                                               
-                                               if (soundact->sound->flags & 
SOUND_FLAGS_3D)
-                                                       sndobj->Set3D(true);
-                                               else
                                                        sndobj->Set3D(false);
+                                               }
                                        }
-                                       else {
-                                               /* dummy values for a NULL sound
-                                                * see editsound.c - defaults 
are unlikely to change soon */
-                                               sndobj->SetRollOffFactor(1.0);
-                                               sndobj->SetGain(1.0);
-                                               sndobj->SetPitch(1.0);
-                                               
sndobj->SetLoopMode(SND_LOOP_OFF);
-                                               sndobj->SetHighPriority(false);
-                                               sndobj->Set3D(false);
-                                       }
-                                       
                                        KX_SoundActuator* tmpsoundact = 
                                                new KX_SoundActuator(gameobj, 
                                                sndobj,
@@ -460,7 +461,8 @@
                                        
                                        tmpsoundact->SetName(bact->name);
                                        baseact = tmpsoundact;
-                                       soundscene->AddObject(sndobj);
+                                       if (sndobj)
+                                               soundscene->AddObject(sndobj);
                                }
                                break;
                        }

Modified: trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp 2008-08-28 
07:03:23 UTC (rev 16278)
+++ trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp 2008-08-28 
08:13:58 UTC (rev 16279)
@@ -69,11 +69,11 @@
 
 KX_SoundActuator::~KX_SoundActuator()
 {
-       //m_soundScene->RemoveObject(this->m_soundObject);
-       //(this->m_soundObject)->DeleteWhenFinished();
-       m_soundScene->RemoveActiveObject(m_soundObject);
-//     m_soundScene->DeleteObjectWhenFinished(m_soundObject);
-       m_soundScene->DeleteObject(m_soundObject);
+       if (m_soundObject)
+       {
+               m_soundScene->RemoveActiveObject(m_soundObject);
+               m_soundScene->DeleteObject(m_soundObject);
+       }
 }
 
 
@@ -82,9 +82,12 @@
 {
        KX_SoundActuator* replica = new KX_SoundActuator(*this);
        replica->ProcessReplica();
-       SND_SoundObject* soundobj = new SND_SoundObject(*m_soundObject);
-       replica->setSoundObject(soundobj);
-       m_soundScene->AddObject(soundobj);
+       if (m_soundObject)
+       {
+           SND_SoundObject* soundobj = new SND_SoundObject(*m_soundObject);
+               replica->setSoundObject(soundobj);
+               m_soundScene->AddObject(soundobj);
+       }
        
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
@@ -104,6 +107,9 @@
 
        RemoveAllEvents();
 
+       if (!m_soundObject)
+               return false;
+
        if (m_pino)
        {
                bNegativeEvent = true;
@@ -287,6 +293,10 @@
 
 PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
+       if (!m_soundObject)
+       {
+               return PyString_FromString("");
+       }
        STR_String objectname = m_soundObject->GetObjectName();
        char* name = objectname.Ptr();
        
@@ -301,7 +311,8 @@
 
 PyObject* KX_SoundActuator::PyStartSound(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       m_soundObject->StartSound();    
+       if (m_soundObject)
+               m_soundObject->StartSound();    
        Py_Return;
 }         
 
@@ -309,7 +320,8 @@
 
 PyObject* KX_SoundActuator::PyPauseSound(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       m_soundObject->PauseSound();    
+       if (m_soundObject)
+               m_soundObject->PauseSound();    
        Py_Return;
 } 
 
@@ -317,7 +329,8 @@
 
 PyObject* KX_SoundActuator::PyStopSound(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       m_soundObject->StopSound();     
+       if (m_soundObject)
+               m_soundObject->StopSound();     
        Py_Return;
 }
 
@@ -329,7 +342,8 @@
        if (!PyArg_ParseTuple(args, "f", &gain))
                return NULL;
        
-       m_soundObject->SetGain(gain);
+       if (m_soundObject)
+               m_soundObject->SetGain(gain);
        
        Py_Return;
 }         
@@ -338,7 +352,7 @@
 
 PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       float gain = m_soundObject->GetGain();
+       float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f;
        PyObject* result = PyFloat_FromDouble(gain);
        
        return result;
@@ -352,7 +366,8 @@
        if (!PyArg_ParseTuple(args, "f", &pitch))
                return NULL;
        
-       m_soundObject->SetPitch(pitch);
+       if (m_soundObject)
+               m_soundObject->SetPitch(pitch);
        
        Py_Return;
 }         
@@ -361,7 +376,7 @@
 
 PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       float pitch = m_soundObject->GetPitch();
+       float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0;
        PyObject* result = PyFloat_FromDouble(pitch);
        
        return result;
@@ -375,7 +390,8 @@
        if (!PyArg_ParseTuple(args, "f", &rollofffactor))
                return NULL;
        
-       m_soundObject->SetRollOffFactor(rollofffactor);
+       if (m_soundObject)
+               m_soundObject->SetRollOffFactor(rollofffactor);
 
        Py_Return;
 }         
@@ -384,7 +400,7 @@
 
 PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       float rollofffactor = m_soundObject->GetRollOffFactor();
+       float rollofffactor = (m_soundObject) ? 
m_soundObject->GetRollOffFactor() : 1.0;
        PyObject* result = PyFloat_FromDouble(rollofffactor);
        
        return result;
@@ -398,7 +414,8 @@
        if (!PyArg_ParseTuple(args, "i", &looping))
                return NULL;
        
-       m_soundObject->SetLoopMode(looping);
+       if (m_soundObject)
+               m_soundObject->SetLoopMode(looping);
        
        Py_Return;
 }         
@@ -407,7 +424,7 @@
 
 PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, 
PyObject* kwds)
 {
-       int looping = m_soundObject->GetLoopMode();
+       int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : 
SND_LOOP_OFF;
        PyObject* result = PyInt_FromLong(looping);
        
        return result;
@@ -425,7 +442,8 @@
        if (!PyArg_ParseTuple(args, "fff", &pos[0], &pos[1], &pos[2]))
                return NULL;
        
-       m_soundObject->SetPosition(pos);
+       if (m_soundObject)
+               m_soundObject->SetPosition(pos);
        
        Py_Return;
 }         
@@ -442,7 +460,8 @@
        if (!PyArg_ParseTuple(args, "fff", &vel[0], &vel[1], &vel[2]))
                return NULL;
        
-       m_soundObject->SetVelocity(vel);
+       if (m_soundObject)
+               m_soundObject->SetVelocity(vel);
        
        Py_Return;
 }         
@@ -465,7 +484,8 @@
        if (!PyArg_ParseTuple(args, "fffffffff", &ori[0][0], &ori[0][1], 
&ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], 
&ori[2][2]))
                return NULL;
        
-       m_soundObject->SetOrientation(ori);
+       if (m_soundObject)
+               m_soundObject->SetOrientation(ori);
        
        Py_Return;
 }


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to