Game Development Community

TGE crash on death, dynamically casted player object

by napiersabre · in Torque Game Engine · 05/29/2007 (5:33 pm) · 0 replies

I have a GUI object set up as normal. The onRender function starts with --

GameConnection* conn = GameConnection::getConnectionToServer();  
if (!conn)
      return;
ShapeBase* control = conn->getControlObject();
if (!control) 
      return;

I then cast the shapebase control object to player --

Player* playerObj = dynamic_cast<Player*>(control);

I can now obviously call public player member functions, playerObj->whatever(). These function calls work great until the player dies, at which point the program crashes. I have determined that the crash occurs for any player function and that it occurs exactly at this function call.

I presume some sort of memory bookkeeping is done that makes subsequent calls until the player is respawned invalid, but I can't quite figure out what I need to check. I've tried making player member calls dependent upon successful control (shapebase) function calls, like getDamageLevel, isDestroyed, isControlled, etc. but have had no luck.

I know I'm missing something really simple.