Destroy Shot body in callback

Springare

15-01-2008 18:24:05

hi me again ^^,

I got another problem whit my callbacks... been trying to figure it out all day. in my callback I check what my shot hits and then do some things then after I want to delete the shot from the memory. But how do I delete it? I tried to call "delete" on the actor I get in the callback but it crashs and tried disable but then it just becomes invisible and won't update but it still takes up memory so after a while I get like 2 fps '^^

here's my callback class :P
class tankShotCallback : public GroupCallback::InheritedCallback
{
public :

tankShotCallback()
{

}

void onStartTouch(Actor *a, Actor *b)
{
Body * ad = static_cast<Body*>(a);
String temp = b->getName();
if(temp == "Level01.mesh") // if the shot hits the ground
{
/////
// Removes/Deletes the shot
//////

//ad->_destroyActor();
//delete ad;
//delete a;
//a->_destroyActor();
ad->disable();

}
else if(temp == "M60Body.mesh") // if the shot hit's player 1 (red tank)
{
/////////////////
//Tank looses health
/////////////////


/////
// Removes/Deletes the shot
//////
//ad->_destroyActor();
//delete ad;
//delete a;
//a->_destroyActor();
ad->disable();

}
}

void onEndTouch(Actor *a, Actor *b)
{


}

void onTouch(Actor *a, Actor *b)
{


}
};


is it possible to delete the shot in the callback??

betajaen

15-01-2008 19:38:57

No. PhysX is still using the NxActor and probably NxOgre as well. You should add the Actor to the "ThingsI'mGonnaDeleteSoon" list instead.

Springare

15-01-2008 23:25:41

oh okey, but then what should I do? I have a
vector <Body*> m_vShotVector

wich cotains all bodys of all the shots... so what can I call on a body to delete it ?

m_vShotVector[i]->//what here?

betajaen

15-01-2008 23:31:33

It's:

vector<Actor*>

and:

mScene->destroyActor(m_vShotVector[i]->getName());

Springare

16-01-2008 00:04:12

awww still won't work :S it breaks in some strage file called "tidtable.c" wich I never heard of..

it breaks here at the "PFLS_GETVALUE_FUNCTION" =//***
* __set_flsgetvalue - crt wrapper for setting up FlsGetValue pointer in TLS
*
* Purpose:
* This function helps msvcmXX.dll threadstart and threadstartex APIs
* to set FlsGetValue pointer before calling __fls_getvalue.
*
*******************************************************************************/

_CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()
{
#ifndef _M_AMD64
PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE; //<-------- the break was here
if (!flsGetValue)
{
flsGetValue = _decode_pointer(gpFlsGetValue);
TlsSetValue(__getvalueindex, flsGetValue);
}
return flsGetValue;
#else /* _M_AMD64 */
return NULL;
#endif /* _M_AMD64 */
}



**EDIT**
just before u told me to use a actor vector I tried some other ways but still would't work...


// /*Try 1*/
// //mSceneMgr->destroySceneNode(m_vShotVector[i]->getNode()->getName());
// //mSceneMgr->destroyEntity(m_vShotVector[i]->getEntity());
// //pNxScene->destroyActor(m_vShotVector[i]->getNxActor()->getName());
//
// /*Try 2*/
// //pNxScene->destroyBody(m_vShotVector[i]->getName());

// /*Try 3*/
// //delete m_vShotVector[i];

betajaen

16-01-2008 11:12:14

Is "m_vShotVector" NULL? or a random pointer?

Do check with "m_vShotVector->getName()".

Springare

16-01-2008 11:58:36

I've checked that it gets all the shot I want to delete. and I can get the name by using the getName() so it should work =/

betajaen

16-01-2008 12:02:09

And your deleting the Actor outside the callback and preferably in a frameEnded?

Springare

16-01-2008 12:08:32

at the moment I use it in ogres update