Game of life tutorial - EXC_BAD_ACCESS (code = 1)

Hello Guys,

I am learning cocos2d-x and loving it! I am following game of life tutorial at this link: https://www.makeschool.com/tutorials/learn-cocos-studio-and-c-by-building-the-game-of-life/game-of-life-code

So far so good, but I get stucked when compiling my code, it says "EXC_BAD_ACCESS ( code = 1) at this line of code:

cellWidth = gridSprite->getContentSize().width / float(COLUMNS);

the full lines is:

  Sprite* gridSprite = this->getChildByName<Sprite*>("grid");
    cellWidth = gridSprite->getContentSize().width / float(COLUMNS);
    cellHeight = gridSprite->getContentSize().height / float(ROWS);

I tried for a while to find this alone, but I guess my C++ debug skills are still nearly nothing :smile:

Any help? Thank you

Oh nvm, I realized that my “gridSprite” is NULL somehow, I guess I can solve it then

I would recommend tagging you nodes with setTag(int) feature, and the getting those nodes back by getChildByTag()

So for you it should look like this:

Sprite *gridSprite = (Sprite *)getChildByTag(tag);

Hey grueth, indeed it was wrong name under (“grid”) , I had the name uppercase in cocos studios as “Grid”.

Thanks for help.

Perhaps I can use same topic to ask another question, since I started to add C++ code to my project, Running on Android (via cocos studio) stopped working, in order to compile Android I am forced to mount the project on Eclipse? or it should always work via cocos studio (which is the same as running via console I think)

thanks