![How to keep away from a crash when when a node is deleted in replace loop? (see instance for clarification) – cocos2d-x How to keep away from a crash when when a node is deleted in replace loop? (see instance for clarification) – cocos2d-x](https://thefuntrove.com/wp-content/uploads/https://discuss.cocos2d-x.org/uploads/default/original/3X/c/9/c9a024cd3656916ac85bb3a01034f8075bc8f827.png)
[ad_1]
Hi,
let me wright this pseudo code first after which clarify. Say GameScene is a sport degree. GameScene has a non-public Sprite member known as _mySprite declared within the header as nullPtr. In the replace methodology I’m making an attempt to print one thing if the sprite exist, after which delete that sprite.
bool GameScene::init()
{
//... code
_mySprite = Sprite::create("someTexture.png") ;
_mySprite->setPosition(500, 500);
addChild(_mySprite);
//... code
}
void GameScene::replace(float dt)
{
if (_mySprite)
{
CCLOG("test level A");
_mySprite->removeFromParentAndCleanup(true);
}
}
And that is the error
test level A
test level A
Exception thrown: learn entry violation.
this->_testSprite->**** was 0xDDDDDDDD.
My understanding is that 0xDDDDDDDD signifies that the pointer is null since I eliminated it with removeFromParentAndCleanup(true), proper? But if I set the situation to enter the scope provided that _testSprite exist (if (_mySprite)), why is it getting into once more after take away it?
My answer is to create a vector holding that sprite, and if I take away it, I delete it from the vector and the insteado of (if (_mySprite)), I do one thing like (if (myVector.dimension() > 0)). Or perhaps utilizing tags, however I ponder why my try on checking if a pointer isn’t null will not be working. How would you strategy one thing like that?
Thanks
[ad_2]