-1

I have got a strange bug I cannot seem to figure out. I've got a class called SPGamePlayScene. I also have a class called SPPracticeScene with inherits from SPGamePlayScene. I want SPPracticeScene to do all the stuff SPGamePlayScene does in its initializer so Ive overridden it and added some other code to it. However whenever I initialize an SPPracticeScene object, It creates two instead of one. I think it must have something to do with my initializers. below is the initializer for SPGamePlaySCene:

//SPGamePlayScene.m
- (id)initWithSize:(CGSize)size colored:(BOOL)colored {

    if (self = [super initWithSize:size]) {

        //lots of custom setup here

    }
    return self;


}

it looks like a pretty standard initializer to me.

then below is the initializer for SPPracticeScene. it calls its superclass's (SPGamePlayScene) initializer method above and then does some custom setup as well

//SPPracticeScene
- (id)initWithSize:(CGSize)size {

    if (self = [super initWithSize:size colored:NO]) {

        //custom setup here
        //this log runs twice. the memory adress shown is different each time
        NSLog(@"practice scene: %p", self);
    }
    return self;

}

can anybody tell me why its running twice and two different objects are being created?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Stone Preston
  • 1,828
  • 4
  • 20
  • 35
  • Please show more code than this. The snippets you've posted don't seem to show a problem. – sbooth Aug 06 '14 at 01:57
  • 5
    What do you mean "it creates two instead of one"? What symptom tells you that?? – Hot Licks Aug 06 '14 at 01:58
  • I added an NSLog statement to the init method for my practice scene. It outputs twice and each time it outputs the memory address is not the same. – Stone Preston Aug 06 '14 at 02:08
  • 2
    learn how to debug your program with break point – Bryan Chen Aug 06 '14 at 02:13
  • what is a "custom setup"? ill you have your double logging if you comment all "custom setup"? – OgreSwamp Aug 06 '14 at 02:14
  • 2
    If `[SPPracticeScene -initWithSize:]` is called twice, you're probably calling it twice. Set a breakpoint where your `NSLog` is. Then look at the stack trace to see who is calling it each time. Anyway, the problem is not in the code you posted. – Aaron Brager Aug 06 '14 at 02:19
  • alright ill give that a shot. I just figured there was probably an issue with my initializers and thought maybe something was going on with them. but if it looks good to you guys ill go over my code again and see what I can find – Stone Preston Aug 06 '14 at 02:23

1 Answers1

0

ok initially I was creating the scene in viewDidLayout subviews of my viewController. I moved it into viewWillAppear and its no longer being called twice. For some reason viewDidLayoutsubviews is called twice. I have a navigation controller embedded in my view controller, maybe that has something to do with the reason for multiple calls

Stone Preston
  • 1,828
  • 4
  • 20
  • 35