cocos2d iphone - 'NSInvalidArgumentException', reason: '-[MenuScene distance]: when replacing a scene -


in code have made gamemanager singleton has method responsible changing scenes. first scene call menuscene after replace gamescene. when console output shows:

2013-10-07 19:40:55.895 mygame[56164:a0b] -[menuscene distance]: unrecognized selector sent instance 0xb460690 2013-10-07 19:40:56.011 mygame[56164:a0b] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[menuscene distance]: unrecognized selector sent instance 0xb460690' 

from log, don't understand why -[menuscene distance] ... because distance property of gamescene not menuscene.

below gamemanager method changing scenes:

-(void)runscenewithid:(scenetypes)sceneid { scenetypes oldscene = currentscene; currentscene = sceneid; //nsstring* str; id scenetorun = nil; switch (sceneid) {     case kbeginscene:         scenetorun = [beginscene node];          break;     case kgamescene:         scenetorun = [gamescene node];         break;      case kmenuscene:         scenetorun = [menuscene node];         break;      default:         cclog(@"unknown id, cannot switch scenes");         return;         break; }  if (scenetorun == nil) {     // revert back, since no new scene found     currentscene = oldscene;     return; }   if ([[ccdirector shareddirector] runningscene] == nil) {     [[ccdirector shareddirector] runwithscene:scenetorun];  } else {      [[ccdirector shareddirector] replacescene:scenetorun]; } 

}

also call replace scene in layer class part of menuscene. see below:

-(void)startgamescene { [[gamemanager sharedgamemanager] runscenewithid:kgamescene];  } 

please help.

you message because distance message sent menuscene instance doesn't have selector (gamescene apparently).

so somewhere in scene managing singleton goes wrong , still (or already) have menuscene instance expect have gamescene instance.

add exception breakpoint in xcode see message coming from.

ps: very careful when managing scenes in global instance singleton. leak memory if keep strong reference scene (or node matter) in global instance/variable. make sure every scene has dealloc method implemented log see deallocate.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -