diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-06-01 22:41:58 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-06-01 22:41:58 +0400 |
commit | 4c7a02f6a1d517f8af6e4cf9200c067e9c71cf78 (patch) | |
tree | ca972409490c7c1d606b5859815946b7230d47b8 /source | |
parent | 2a3627e338516646d3e68f4db6147a80410bcf1f (diff) |
BGE: memory leak in Random actuator + make actuator truly random when seed=0 in the UI. When running the game, seed 0 is replaced by a random seed accessible through Python in seed attribute of the actuator. Other seed value will be left unchanged and will generate fixed pseudo random series.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Converter/KX_ConvertActuators.cpp | 5 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_RandomActuator.cpp | 10 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_RandomActuator.h | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 2b832996c45..ea812a71fdd 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -954,6 +954,11 @@ void BL_ConvertActuators(char* maggiename, = (bRandomActuator *) bact->data; unsigned long seedArg = randAct->seed; + if (seedArg == 0) + { + seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0); + seedArg ^= (intptr_t)randAct; + } SCA_RandomActuator::KX_RANDOMACT_MODE modeArg = SCA_RandomActuator::KX_RANDOMACT_NODEF; SCA_RandomActuator *tmprandomact; diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 1bc4487b5bf..a722590dd10 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -58,7 +58,6 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj, m_parameter2(para2), m_distribution(mode) { - // m_base is never deleted, probably a memory leak! m_base = new SCA_RandomNumberGenerator(seed); m_counter = 0; enforceConstraints(); @@ -68,7 +67,7 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj, SCA_RandomActuator::~SCA_RandomActuator() { - /* intentionally empty */ + m_base->Release(); } @@ -81,6 +80,13 @@ CValue* SCA_RandomActuator::GetReplica() return replica; } +void SCA_RandomActuator::ProcessReplica() +{ + SCA_IActuator::ProcessReplica(); + // increment reference count so that we can release the generator at the end + m_base->AddRef(); +} + bool SCA_RandomActuator::Update() diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index 310e8a7fbf9..59863589b60 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -91,6 +91,7 @@ class SCA_RandomActuator : public SCA_IActuator virtual bool Update(); virtual CValue* GetReplica(); + virtual void ProcessReplica(); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ |