Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2008-08-28 12:13:58 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2008-08-28 12:13:58 +0400
commitc8d0a540f5372850237ac699dce753d7bba9c6df (patch)
tree568332fed7097b2696984644b1bf9e6f0ffecf82 /source/gameengine
parentf88c5d972130e7bcde3fdd289e91546c5946c888 (diff)
BGE patch: fix division by 0 error when sound sample cannot be loaded in sound actuator.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp78
-rw-r--r--source/gameengine/Ketsji/KX_SoundActuator.cpp64
2 files changed, 82 insertions, 60 deletions
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
index 9ec8bdd91fc..7e976beaf44 100644
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ b/source/gameengine/Converter/KX_ConvertActuators.cpp
@@ -406,50 +406,51 @@ void BL_ConvertActuators(char* maggiename,
/* 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 @@ void BL_ConvertActuators(char* maggiename,
tmpsoundact->SetName(bact->name);
baseact = tmpsoundact;
- soundscene->AddObject(sndobj);
+ if (sndobj)
+ soundscene->AddObject(sndobj);
}
break;
}
diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp
index 34a3baec093..f75a1ee5c62 100644
--- a/source/gameengine/Ketsji/KX_SoundActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp
@@ -69,11 +69,11 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
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 @@ CValue* KX_SoundActuator::GetReplica()
{
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 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
RemoveAllEvents();
+ if (!m_soundObject)
+ return false;
+
if (m_pino)
{
bNegativeEvent = true;
@@ -287,6 +293,10 @@ PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObje
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::PyGetFilename(PyObject* self, PyObject* args, PyObje
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::PyStartSound(PyObject* self, PyObject* args, PyObjec
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::PyPauseSound(PyObject* self, PyObject* args, PyObjec
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 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject*
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::PySetGain(PyObject* self, PyObject* args, PyObject*
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 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject*
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::PySetPitch(PyObject* self, PyObject* args, PyObject*
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 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P
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::PySetRollOffFactor(PyObject* self, PyObject* args, P
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 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec
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::PySetLooping(PyObject* self, PyObject* args, PyObjec
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 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje
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 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje
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 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO
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;
}