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>2009-05-23 18:46:43 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-05-23 18:46:43 +0400
commit5441323dca30c169d1ecb726d26e8cb4c5f4994d (patch)
tree1bcd7b2460f8980bacb03232498cdb7a02b9ba36 /source/gameengine/GameLogic
parent6d8d7cd768f292a7fbbcecaf5f1cbc3090973f12 (diff)
BGE: fix memleaks.
SCA_RandomActuator: The random generator was shared between replicas and not deleted. Added ref counting between replicas to allow deletion at the end. KX_Camera: The scenegraph node was not deleted for temporary cameras (ImageMirror and shadow), causing 500 bytes leak per frame and per shadow light. KX_GameActuator: Global dictionary buffer was not deleted after saving. KX_MotionState: The motion state for compound child was not deleted KX_ReplaceMeshActuator: The mesh was unnecessarily converted for each actuator and not deleted, causing large memleak. After these fix, YoFrankie runs without memleak.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp1
-rw-r--r--source/gameengine/GameLogic/SCA_RandomNumberGenerator.h13
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.cpp10
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.h1
4 files changed, 22 insertions, 3 deletions
diff --git a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
index 06b5cca6ce9..0267cc8ebbf 100644
--- a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
@@ -59,6 +59,7 @@
SCA_RandomNumberGenerator::SCA_RandomNumberGenerator(long seed) {
// int mti = N + 1; /*unused*/
m_seed = seed;
+ m_refcount = 1;
SetStartVector();
}
diff --git a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h
index b9311d31af6..842a0331752 100644
--- a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h
+++ b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h
@@ -36,6 +36,9 @@
class SCA_RandomNumberGenerator {
+ /* reference counted for memleak */
+ int m_refcount;
+
/** base seed */
long m_seed;
@@ -56,6 +59,16 @@ class SCA_RandomNumberGenerator {
float DrawFloat();
long GetSeed();
void SetSeed(long newseed);
+ SCA_RandomNumberGenerator* AddRef()
+ {
+ ++m_refcount;
+ return this;
+ }
+ void Release()
+ {
+ if (--m_refcount == 0)
+ delete this;
+ }
};
#endif /* __KX_RANDOMNUMBERGENERATOR */
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
index 3c04173d10e..d5cbeef01ae 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
@@ -50,7 +50,6 @@ SCA_RandomSensor::SCA_RandomSensor(SCA_EventManager* eventmgr,
PyTypeObject* T)
: SCA_ISensor(gameobj,eventmgr, T)
{
- // m_basegenerator is never deleted => memory leak
m_basegenerator = new SCA_RandomNumberGenerator(startseed);
Init();
}
@@ -59,7 +58,7 @@ SCA_RandomSensor::SCA_RandomSensor(SCA_EventManager* eventmgr,
SCA_RandomSensor::~SCA_RandomSensor()
{
- /* Nothing to be done here. */
+ m_basegenerator->Release();
}
void SCA_RandomSensor::Init()
@@ -74,13 +73,18 @@ void SCA_RandomSensor::Init()
CValue* SCA_RandomSensor::GetReplica()
{
CValue* replica = new SCA_RandomSensor(*this);
- // replication copies m_basegenerator pointer => share same generator
// this will copy properties and so on...
replica->ProcessReplica();
return replica;
}
+void SCA_RandomSensor::ProcessReplica()
+{
+ SCA_ISensor::ProcessReplica();
+ // increment reference count so that we can release the generator at this end
+ m_basegenerator->AddRef();
+}
bool SCA_RandomSensor::IsPositiveTrigger()
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h
index 27b41841f0b..b2bf2440966 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.h
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.h
@@ -52,6 +52,7 @@ public:
PyTypeObject* T=&Type);
virtual ~SCA_RandomSensor();
virtual CValue* GetReplica();
+ virtual void ProcessReplica();
virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void Init();