c++ - Child objects are (seemingly) randomly set to NULL or an 'illegal object'; how to debug that? -


i use cocos2d-x game porting cocos2d-iphone. original programmer seems have used 'feature' of objective-c not crash on calls nil objects way lot of sloppy things.

if related don't know, however, in code never call release() manually , not delete or that. don't call ->removeobject() @ (although not result in same issue have).

now problem: when game running, @ random moments (they won't random seem way obviously) child nodes set null. , not affect code als cocos2d internals. example:

    cclog("----------------");     for(int j = 0; j < this->getchildren()->count(); j++)     {         ccobject *child = this->getchildren()->objectatindex(j);         enemysprite *enemy = dynamic_cast<enemysprite*>(child);         if (enemy != null) {             cclog("enemy tag %d found", enemy->gettag());         }     }     enemysprite *enemy = dynamic_cast<enemysprite*>(this->getchildbytag(i));     if (enemy == null) {          cclog("now enemy %d null :(", i);     } 

in getchildren() look, enemies tags there , print this;

  • enemy tag 1000 found
  • enemy tag 1001 found
  • enemy tag 1002 found

during game it'll show lot, until shows this;

  • enemy tag 1000 found
  • enemy tag 1001 found
  • enemy tag 1002 found
  • now enemy 1001 null :(

and crashes.

in mind, should impossible above code checked, verified , printed object...

but more interesting (maybe me, maybe it's stupid mistake),

 this->getchildbytag(i) 

randomly goes wrong internally well; traversing children, it'll find null , conk out on cocos2d internal code:

        if(pnode && pnode->m_ntag == atag)             return pnode; 

the pnode not null (that's why asserts not trigger) looks this:

http://o7.no/137jxc4 (screenshot)

the cocos2d::cccopying thing stuff of nightmares me in project; every time see know wrong , have no clue how find is.

i added breakpoint @ release() delete line; it's not being called. , i, said, not doing manually.

i use xcode / ios debug, behavior same on android (but on computer eclipse slower xcode, during debugging).

i understand difficult give me solution / cause, however; happy if can tell me how attack issue. happens randomly throughout (quite large) codebase , i'm @ loss how find issue...

i hope can help!

at times dynamic_cast returns 0 tough argument not 0. happens example when you're casting super class subclass (so called "down casting"). check tutorial more information: http://www.cplusplus.com/doc/tutorial/typecasting/

i can imagine if elements in list have generic (unrelated) super type, can problem in case.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -