Revision: 20564
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20564
Author: ben2610
Date: 2009-06-01 20:41:58 +0200 (Mon, 01 Jun 2009)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
Modified: trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
2009-06-01 17:23:35 UTC (rev 20563)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertActuators.cpp
2009-06-01 18:41:58 UTC (rev 20564)
@@ -954,6 +954,11 @@
= (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;
Modified: trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
2009-06-01 17:23:35 UTC (rev 20563)
+++ trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
2009-06-01 18:41:58 UTC (rev 20564)
@@ -58,7 +58,6 @@
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()
{
- /* intentionally empty */
+ m_base->Release();
}
@@ -81,8 +80,15 @@
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()
{
//bool result = false; /*unused*/
Modified: trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
2009-06-01 17:23:35 UTC (rev 20563)
+++ trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.h
2009-06-01 18:41:58 UTC (rev 20564)
@@ -91,6 +91,7 @@
virtual bool Update();
virtual CValue* GetReplica();
+ virtual void ProcessReplica();
/*
--------------------------------------------------------------------- */
/* Python interface
---------------------------------------------------- */
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs