Game Development Community

Can't delete objects!!! Need help

by Yang Deqian · in Torque Game Engine Advanced · 09/10/2007 (7:56 am) · 6 replies

I write a Console Function in \Torque\TGEA_1_0_3\engine\game\showTSShape.cpp just under "ConsoleFunctionGroupBegin( ShowTool, "Functions for controlling the show tool.");" line 836, and called it in mod "show"'s gui "tsShowGui.gui" by created a ButtonCtrl which command is clearAll().

ConsoleFunction( clearAll, void, 0, 0, "Clear All Dts!" )
{
// get the show set...
SimSet * set = static_cast(Sim::findObject("showSet"));

// update the instances...
if (set)
for (SimSet::iterator itr = set->begin(); itr!=set->end(); itr++)
{
static_cast(*itr)->deleteObject(); //here the @ is
showUpdateThreadControl();
}
else
;
showUpdateThreadControl();

// make sure detail slider is set correctly
setDetailSlider();
}

it seems that @ does nothing ! when i first called the function, nothing happened, but a "SimManager::deleteObject:Object in the process of being removed" comes when i called it the second time!

I realy don't know where i did wrong! please help and point it out !

Thanks a lot for all you !

#1
09/10/2007 (8:02 am)
There are a couple of technique issues with what you are trying to do:

--When you are iterating over a set, and want to delete objects from that set, you should iterate backwards.
--Although in theory things should work fine if you never put anything in your set except for SHowTSShape's, you really should be using dynamic_cast instead of static_cast, and making sure the pointer is valid before attempting the delete.

I don't understand what you mean by "@ does nothing!". It's in a comment within your code--what do you expect it to do?
#2
09/10/2007 (8:53 am)
"@" means that line of code which is identifiered with "@", I want when i called clearAll function, it delete all the dts loaded before which are displaying. The screen should looks like when we just run the mod "show", no dts playing on it.( before we press button " Load Shape" to load a dts file )

the second ver code:

ConsoleFunction( clearAll, void, 1, 2, "Clear ALL!")
{
// get the show set...
SimSet * set = dynamic_cast(Sim::findObject("showSet"));

// update the instances...
if (set)
for (SimSet::iterator itr = set->end(); itr!=set->begin(); itr--)
{
dynamic_cast(*itr)->deleteObject(); //here the @ is
showUpdateThreadControl();
}
else
;
showUpdateThreadControl();

// make sure detail slider is set correctly
setDetailSlider();
}

To despair, it still doesn't work... an error occours :
0x0012e84c 's std::__non_rtti_object.
#3
09/10/2007 (9:30 am)
I admit I could be wrong about the dynamic_cast--I was using general programming practices in Torque that may not be applicable to iterators. I can't find any code in the main engines that actually do what I said, so you can go back to using the static for now.



It's possible that your call to showUpdateThreadControl() in each iteration of the loop is interfering with the set itself, but that's just a guess.
#4
09/10/2007 (5:05 pm)
^_^ Thanks your help, but showUpdateThreadControl() is not at the point, i find out that in function showShapeLoad the Torque Engine Code
if (show->shapeLoaded())
{
show->setPosition(pos+vec);
show->registerObject();
Sim::getRootGroup()->addObject(show);
}

seems has a little bug !?

It registerObject with noname, ( by overloaded registerObject(void) ) although the registerObject(void) function does exits, but Objects assigned with no name might result in a mistake while deleting.

I placed registerObject(); by registerObject( somename ); /* char * somename */ and it works! But to strange....I have to call clearAll function twice that the dts despares from screen. Still finding the reason..
#5
09/10/2007 (9:45 pm)
It seems that if select a *.dts file from the file list which occurs when press down button "LoadShape" and double click it will course load the dts file twice. Somebody knows anything about it?????
#6
09/11/2007 (12:07 am)
It realy does this if you double click the .dts file from the directory file list to load a dts file.
in ":\Torque\TGEA_1_0_3\engine\gui\controls\guiDirectoryFileListCtrl.cpp"


void GuiDirectoryFileListCtrl::onMouseDown(const GuiEvent &event)
{
Parent::onMouseDown( event );

if( event.mouseClickCount == 2 && isMethod("onDoubleClick") )
Con::executef(this, 1, "onDoubleClick");

}


Upper function calls it's Parent::onMouseDown( event ); so both it and it's Parent executef( this, 1, "onDoubleClick"); As a result, the dts file loaded twice.