Friday, July 1, 2022
HomeGame DevelopmentEasy methods to take away a participant when lifeless with out null...

Easy methods to take away a participant when lifeless with out null pointer crash – cocos2d-x


Hello,
I’ve a technique that examine collisions between the participant sprite and the enemies.

void CollisionSystem::runPlayerCollision(Vector<Sprite*>& enemies, Sprite* playerSprite)
{
    // I've a loop that checks the collisions and if a collisio is discovered it does this
    CCLOG("Collision discovered");
    playerSprite->removeFromParentAndCleanup(true);
    playerSprite->launch();
}

My understanding is that removeFromParentAndCleanup doesn’t delete the pointer. So I add a launch() to delete it.
Now that is what I don’t get. In the principle replace() loop of the sport I added this

if (GameGlobals::playerSprite != nullptr)
{
     CCLOG("sport working");
     collisionSystemInstance->runPlayerCollision(GameGlobals::enemies,  Sport:Globals::participant)
}

The output is

sport working
sport working
sport working
sport working
sport working
"Collision discovered"

Exception thrown: learn entry violation.
playerSprite->**** was 0xDDDDDDDD.

So, the collision methodology is doing the work proper as a result of the video games retains working whereas the playerSprite exists. And when there’s a collision, the LOG “Collision discovered” proves it’s working okay, and therefor it deletes the playerSprite pointer. The error playerSprite->**** was 0xDDDDDDDD occurs inside
collisionSystemInstance->runPlayerCollision(GameGlobals::enemies, Sport:Globals::participant), however why is it working that, if I said to working solely if the GameGlobals::playerSprite != nullptr??

The error implies that playerSprite was delete proper? which is what I need when it collides. However the situation to run the collision methodology is that the playerSprite exists, and it doesn’t, so why is it working it? I’m confused.

R


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments