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.
This commit is contained in:
@@ -954,6 +954,11 @@ void BL_ConvertActuators(char* maggiename,
|
|||||||
= (bRandomActuator *) bact->data;
|
= (bRandomActuator *) bact->data;
|
||||||
|
|
||||||
unsigned long seedArg = randAct->seed;
|
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_MODE modeArg
|
||||||
= SCA_RandomActuator::KX_RANDOMACT_NODEF;
|
= SCA_RandomActuator::KX_RANDOMACT_NODEF;
|
||||||
SCA_RandomActuator *tmprandomact;
|
SCA_RandomActuator *tmprandomact;
|
||||||
|
@@ -58,7 +58,6 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
|
|||||||
m_parameter2(para2),
|
m_parameter2(para2),
|
||||||
m_distribution(mode)
|
m_distribution(mode)
|
||||||
{
|
{
|
||||||
// m_base is never deleted, probably a memory leak!
|
|
||||||
m_base = new SCA_RandomNumberGenerator(seed);
|
m_base = new SCA_RandomNumberGenerator(seed);
|
||||||
m_counter = 0;
|
m_counter = 0;
|
||||||
enforceConstraints();
|
enforceConstraints();
|
||||||
@@ -68,7 +67,7 @@ SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
|
|||||||
|
|
||||||
SCA_RandomActuator::~SCA_RandomActuator()
|
SCA_RandomActuator::~SCA_RandomActuator()
|
||||||
{
|
{
|
||||||
/* intentionally empty */
|
m_base->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +80,13 @@ CValue* SCA_RandomActuator::GetReplica()
|
|||||||
return replica;
|
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 SCA_RandomActuator::Update()
|
||||||
|
@@ -91,6 +91,7 @@ class SCA_RandomActuator : public SCA_IActuator
|
|||||||
virtual bool Update();
|
virtual bool Update();
|
||||||
|
|
||||||
virtual CValue* GetReplica();
|
virtual CValue* GetReplica();
|
||||||
|
virtual void ProcessReplica();
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
/* Python interface ---------------------------------------------------- */
|
/* Python interface ---------------------------------------------------- */
|
||||||
|
Reference in New Issue
Block a user