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-04-27 00:41:25 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2008-04-27 00:41:25 +0400
commitbc059cb8b2b8b09553e4d02b4bcccd67ff73d8fd (patch)
treeee9bc078e5878197018e08ec609fc527bab3f6eb /source/gameengine/GameLogic
parentc8376869b1a521c903a6f8d1be49e48c2966df70 (diff)
BGE bug: crash when an object being tracked-to is deleted (bad practice anyway). Fix by creating a generic cross reference between actuators (only TrackTo uses it at the moment) and objects so that the actuator is informed when the target object is deleted
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.h9
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp23
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.h3
3 files changed, 35 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h
index bff32dcebaa..b802aa4b298 100644
--- a/source/gameengine/GameLogic/SCA_IActuator.h
+++ b/source/gameengine/GameLogic/SCA_IActuator.h
@@ -47,6 +47,15 @@ public:
PyTypeObject* T =&Type);
/**
+ * UnlinkObject(...)
+ * Certain actuator use gameobject pointers (like TractTo actuator)
+ * This function can be called when an object is removed to make
+ * sure that the actuator will not use it anymore.
+ */
+
+ virtual bool UnlinkObject(SCA_IObject* clientobj) { return false; }
+
+ /**
* Update(...)
* Update the actuator based upon the events received since
* the last call to Update, the current time and deltatime the
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
index 465dd981406..6df9e23f3fa 100644
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ b/source/gameengine/GameLogic/SCA_IObject.cpp
@@ -62,6 +62,10 @@ SCA_IObject::~SCA_IObject()
((CValue*)(*itc))->Release();
}
SCA_ActuatorList::iterator ita;
+ for (ita = m_registeredActuators.begin(); !(ita==m_registeredActuators.end()); ++ita)
+ {
+ (*ita)->UnlinkObject(this);
+ }
for (ita = m_actuators.begin(); !(ita==m_actuators.end()); ++ita)
{
((CValue*)(*ita))->Release();
@@ -118,7 +122,24 @@ void SCA_IObject::AddActuator(SCA_IActuator* act)
m_actuators.push_back(act);
}
+void SCA_IObject::RegisterActuator(SCA_IActuator* act)
+{
+ // don't increase ref count, it would create dead lock
+ m_registeredActuators.push_back(act);
+}
+void SCA_IObject::UnregisterActuator(SCA_IActuator* act)
+{
+ SCA_ActuatorList::iterator ita;
+ for (ita = m_registeredActuators.begin(); ita != m_registeredActuators.end(); ita++)
+ {
+ if ((*ita) == act) {
+ (*ita) = m_registeredActuators.back();
+ m_registeredActuators.pop_back();
+ break;
+ }
+ }
+}
void SCA_IObject::SetIgnoreActivityCulling(bool b)
{
@@ -168,6 +189,8 @@ void SCA_IObject::ReParentLogic()
newactuator->SetActive(false);
oldactuators[act++] = newactuator;
}
+ // a new object cannot be client of any actuator
+ m_registeredActuators.clear();
}
diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h
index 8f3e25afa03..4b0fc741b8f 100644
--- a/source/gameengine/GameLogic/SCA_IObject.h
+++ b/source/gameengine/GameLogic/SCA_IObject.h
@@ -55,6 +55,7 @@ protected:
SCA_SensorList m_sensors;
SCA_ControllerList m_controllers;
SCA_ActuatorList m_actuators;
+ SCA_ActuatorList m_registeredActuators; // actuators that use a pointer to this object
static class MT_Point3 m_sDummy;
/**
@@ -79,6 +80,8 @@ public:
void AddSensor(SCA_ISensor* act);
void AddController(SCA_IController* act);
void AddActuator(SCA_IActuator* act);
+ void RegisterActuator(SCA_IActuator* act);
+ void UnregisterActuator(SCA_IActuator* act);
SCA_ISensor* FindSensor(const STR_String& sensorname);
SCA_IActuator* FindActuator(const STR_String& actuatorname);