Home Game Development 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

0
How to keep away from a crash when when a node is deleted in replace loop? (see instance for clarification) – cocos2d-x

[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]

LEAVE A REPLY

Please enter your comment!
Please enter your name here