Thursday, September 21, 2023
HomeSample Page

Sample Page Title


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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments