Game Development Community

SimObject.registerObject questions

by Demolishun · in Torque Game Engine · 01/28/2007 (2:09 pm) · 0 replies

Here is the code behind my question:
bool GuiGridCtrl::onAdd()
{   
   if(!Parent::onAdd())
      return false;
   
   mCellList = new SimSet();
   mCellList->registerObject();
   
   SimGroup *rootGroup = Sim::getRootGroup();
   rootGroup->addObject(mCellList);
   
   return true;
}

void GuiGridCtrl::onRemove()
{  
   if(mCellList)
      mCellList->unregisterObject();

   Parent::onRemove();               
}

I am creating a SimSet in code when I first create my gui object. This is a list that I want to be able to access via script and via C via this object. mCellList is defined this way:
SimObjectPtr<SimSet> mCellList;

I noticed that if I do not check for mCellList during on the onRemove event it segfaults because it is null. The question I have is: Do I even need to unregister the object since it is dynamic and after registration identical to a script produced SimSet? Or should I add the code to delete the object when I delete GuiGridCtrl?

I can imagine an occasion where I might want to keep the SimSet but delete the GuiGridCtrl object. I think originally the mCellList object was a static list defined this way SimSet mCellList and that is why I even have a call to unregisterObject for it.

Thanks,
Frank

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67