Hi everyone,
I'm working on a game and I'm currently working on the part that handles input. Three classes are involved here, there's the ProjectInstance
class which starts the level and stuff, there's a GameController
which will handle the input, and a PlayerEntity
which will be influenced by the controls as determined by the GameController
. Upon starting the level the ProjectInstance creates the GameController
, and it will call its EvaluateControls
method in the Step method, which is called inside the game loop. The EvaluateControls
method looks a bit like this:
void CGameController::EvaluateControls(CInputBindings *pib) {
// if no player yet
if (gc_ppePlayer == NULL) {
// create it
Handle<CPlayerEntityProperties> hep = memNew(CPlayerEntityProperties);
gc_ppePlayer = (CPlayerEntity *)hep->SpawnEntity();
memDelete((CPlayerEntityProperties *)hep);
ASSERT(gc_ppePlayer != NULL);
return;
}
// handles controls here
}
This function is called correctly and the assert never triggers. However, every time this function is called, gc_ppePlayer
is set to NULL. As you can see it's not a local variable going out of scope. The only place gc_ppePlayer
can be set to NULL is in the constructor or possibly in the destructor, neither of which are being called in between the calls to EvaluateControls
. When debugging, gc_ppePlayer
receives a correct and expected value before the return. When I press F10 one more time and the cursor is at the closing brace, the value changes to 0xffffffff. I'm at a loss here, how can this happen? Anyone?