0

So I am trying to do a levelup screen with pushscene/popscene. The pushscene works when it's a blank scene, but not when it's my scene that I want. My scene/layer loads completely with all images and text displaying their exact correct content. After all of the images load there is a EXC BAD ACCESS that doesn't seem to be linked to any particular message being sent. Any help or further diagnostic tests would be appreciated.

I have a version where I commented out the sprites and labels and it still crashes. Is there something big that I'm missing?

EDIT: I've added the [self = [super init]] and [super onEnter] methods and still same problem. It's something else. Any ideas?

EDITEDIT: I think this has something to do with the optionsArray I'm using, not sure what objects need to be retained. The array is a CCArray and contains NSDictionaries of differing capacities

#import "LevelupLayer.h"
#import "GameManager.h"
@implementation LevelupLayer
@synthesize optionsArray,spritesArray;
@synthesize confirmLabel;
@synthesize counter;

 +(id) scene {
    CCScene *scene = [CCScene node];
    CCLayer* layer = [LevelupLayer node];
    [scene addChild:layer];

    return scene;
}

-(void)onEnter
{

counter = 1; // for debugging
//Detemine what levelups are possible
GameManager* gm = [GameManager sharedManager]; //GameManager is a helper that oversees communication between layers and plists
optionsArray = [gm possibleLevelups]; //Access plist and formats data into expected format
[optionsArray retain];
int numPossibilities = [optionsArray count];

//Build Levelup layer based on possible options
CGSize size = [[CCDirector sharedDirector] winSize];
//float positionIncrement = (size.width / numPossibilities) - ((size.width/numPossibilities) * 0.5);
float positionIncrement = (size.width / numPossibilities);
float stripWidth = size.width / numPossibilities;

for (int i = 0; i < numPossibilities; i++) {
    int slot = i+1;
    NSDictionary* optionDict = [optionsArray objectAtIndex:i];
    NSString* name = [optionDict objectForKey:@"name"];
    NSString* title = [optionDict objectForKey:@"title"];
    NSString* description = [optionDict objectForKey:@"description"];


    // Add the sprite
    CCSprite* optionSpite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@.png",name]];
    [self addChild:optionSpite];
    [spritesArray addObject: optionSpite];
    optionSpite.position = CGPointMake(slot * positionIncrement, size.height*0.60);
    [optionSpite setAnchorPoint:CGPointMake(0.5f, 0.5f)];

    // Add the description
    CCLabelBMFont *optionDescription = [CCLabelBMFont labelWithString:description fntFile:@"bodyFont.fnt" width:stripWidth alignment:kCCTextAlignmentCenter];
    [self addChild:optionDescription];
    optionDescription.position = CGPointMake(slot * positionIncrement, size.height*0.30);
    [optionDescription setAnchorPoint:CGPointMake(0.5f, 0.5f)];

    // Add the title
    CCLabelBMFont *optionTitle = [CCLabelBMFont labelWithString:title fntFile:@"titleFont.fnt" width:stripWidth alignment:kCCTextAlignmentCenter];
    [self addChild:optionTitle];
    optionTitle.position = CGPointMake(slot * positionIncrement, size.height*0.90);
    [optionTitle setAnchorPoint:CGPointMake(0.5f, 0.5f)];

}
[self scheduleUpdate]; //Update only prints counter to see how many frames it lasts
}


-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    return YES;
}

-(void) update:(ccTime)delta
{
    CCLOG(@"counter: %d",counter);
    counter++;
}

-(void) onExit
{
    [optionsArray release];
}


@end

`

Pinwheeler
  • 1,061
  • 2
  • 13
  • 26

2 Answers2

1

i don't see any [super onEnter]; or [super init] or anything like that ...that's your problem

First add [super onEnter] on the first line in onEnter.

Second add an init method like this:

-(id)init{
if (self=[super init]){}
}

Third add [super onExit] at the end of your onExit method

skytz
  • 2,201
  • 2
  • 18
  • 23
  • oh my goodness... I can't believe I forgot that. Let me give that a whirl but that looks like my issue. Thanks for the fresh set of eyes – Pinwheeler Dec 01 '12 at 01:17
  • Unfortunately even with the changes the problem persists. Any other ideas? – Pinwheeler Dec 01 '12 at 02:07
  • the only other idea is to move the entire code in the init method . Maybe in doesn't have time to do all that while transitioning so init is a safer solution. Also enable zombie objects to see exactly where it crashes and if it's a problem with the array you mentioned. – skytz Dec 01 '12 at 09:06
  • what is a zombie object, and how do I enable them? Or is this just googleable? – Pinwheeler Dec 01 '12 at 18:58
0

I figured it out, it wasn't anything to do with the code I posted, so sorry about that. It was just a stupid release call to a non-retained array. Retained the array previously and it worked fine. Sorry about crying wolf

Pinwheeler
  • 1,061
  • 2
  • 13
  • 26