Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:02:50+00:00 2026-06-02T10:02:50+00:00

I am creating a custom modal layer. the idea is a user see’s a

  • 0

I am creating a custom modal layer. the idea is a user see’s a city, clicks on said city and accepts or rejects the location.

I use NSMethodSignature to handle the callback so I know whether the user clicked Tick (Accept) or Cross (Reject) buttons in the modal layer.

However, for some reason the app crashes once it invokes the callback and gives me a bad access error when it returns from the modal.

0x000d584e  <+0174>  mov    %eax,0x4(%esp)
0x000d5852  <+0178>  call   0xd6006 <dyld_stub_objc_msgSend>
0x000d5857  <+0183>  mov    -0x8(%ebp),%eax  Thread 1: Program received signal: EXC_BAD_ACCESS

I do not understand why this is happening as the city object is defined in the class.

For example, my .h file has:

@interface MapMenuLayer : CCLayer
{
    CCArray *listOfCities;
    City *city;
}

@property (nonatomic, retain) CCArray *listOfCities;
@property (nonatomic, retain) City *city;

And my .m file has:

@synthesize listOfCities, city;

Later on I define the display each city on the page as clickable CCMenu items. When the user clicks on a city it calls:

-(void) onMenuItem:(id)sender
{
    NSLog(@"sender = %d", [sender tag]);

    self.city = [self.listOfCities objectAtIndex:[sender tag]];    
    NSString *cityName = self.city.name;
    NSLog(@"cityName = %@", cityName);

    // Launch the modal layer
    CityModalLayer *cityModalLayer = [[[CityModalLayer alloc] initWithCity:self.city target:self selector:@selector(onDialogButton:)] autorelease];
    [cityModalLayer show:self];

}

// This is called when the modal is closed or actioned upon
- (void) onDialogButton:(NSInteger)buttonIndex
{
    NSLog(@"onDialogButton:buttonIndex: %d", buttonIndex);

    NSString *cityName = self.city.name;
    NSLog(@"You selected: cityName = %@", cityName);

}

The bad access error occurs when the application flow returns from the modal layer and launches the onDialogButton method is actioned.

It outputs the log fine, but it crashes when it hits the city object. I have no idea why this is happening, it should not be null or causing any formal error.

Okay, so the modal layer is a bit complex, but I cut it down for the purposes of this question:

-(id) initWithCity:(City *)cityObj target:(id)target selector:(SEL)selector
{
    if((self=[super init])) 
    {
        [self initWithColor:ccc4(0, 0, 0, 255)];
        [self setOpacity:80];
        [self setIsTouchEnabled:YES];

        self.city = cityObj;

        // Setup the signature class
    NSMethodSignature *sig = [[target class] instanceMethodSignatureForSelector:selector];
    callback = [NSInvocation invocationWithMethodSignature:sig];
    [callback setTarget:target];
    [callback setSelector:selector];
    [callback retain];

        // -----

        // MENU

// The frames are not in this code, but they do exist

        // Add modal menu
        // Modal Menu (Tick/Cross)
        CCMenu *modalMenu = [CCMenu menuWithItems:nil];    

        CCSprite *closeButtonOff = [CCSprite spriteWithSpriteFrameName:@"closeButton_Off.png"];
        CCSprite *closeButtonOn = [CCSprite spriteWithSpriteFrameName:@"closeButton_On.png"];
        CCSprite *tickButtonOff = [CCSprite spriteWithSpriteFrameName:@"tickButton_Off.png"];
        CCSprite *tickButtonOn  = [CCSprite spriteWithSpriteFrameName:@"tickButton_On.png"];

        // Tick button
        CCMenuItemSprite *tickBtnItem = [CCMenuItemSprite itemFromNormalSprite:tickButtonOff selectedSprite:tickButtonOn target:self selector:@selector(onButtonPressed:)];
        [tickBtnItem setTag:1];
        [tickBtnItem setPosition:CGPointMake(130, -95)];
        [tickBtnItem setIsEnabled:YES];

        // Close button
        CCMenuItemSprite *closeBtnItem = [CCMenuItemSprite itemFromNormalSprite:closeButtonOff selectedSprite:closeButtonOn target:self selector:@selector(onButtonPressed:)];
        [closeBtnItem setTag:0];
        [closeBtnItem setPosition:CGPointMake(-130, -95)];
        [closeBtnItem setIsEnabled:YES];

        // Add stuff to modal
        [modalMenu addChild:closeBtnItem];
        [modalMenu addChild:tickBtnItem]; 

        // Add menu to the modalFrame
        [modalFrame addChild:modalMenu z:2];

        // --

        // Add modalFrame to modalLayer
        [self addChild:modalFrame];    



    } // end if
    return self;

}

// This invokes the action
-(void) onButtonPressed:(id) sender
{
    NSInteger buttonIndex = [sender tag];

    NSLog(@"onButtonPressed: %d", buttonIndex);

    [callback setArgument:&buttonIndex atIndex:1];
    [callback invoke];
    [self removeFromParentAndCleanup:YES];
}


-(void) dealloc
{
    [callback release];
    [super dealloc];
}

I have tracked the issue down to when the callback is invoked, however I do not understand why it is crashing, or giving me the error. It should still have the city object in memory?

What could be causing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:02:51+00:00Added an answer on June 2, 2026 at 10:02 am

    I’ve done it now. It was the autorelease. Which I have removed

    In order to prevent clicks under the modal, or someone pressing on a button lots of times really quickly I put a CoverLayer inside my ModalLayer.m file

    // class that implements a black colored layer that will cover the whole screen 
    // and eats all touches except within the dialog box child
    @interface CoverLayer : CCLayerColor {
    }
    
    @end
    @implementation CoverLayer
    - (id)init {
        self = [super init];
        if (self) {        
            [self initWithColor:ccc4(0,0,0,0) 
                          width:[CCDirector sharedDirector].winSize.width 
                         height:[CCDirector sharedDirector].winSize.height];
            self.isTouchEnabled = YES;
        }
        return self;
    }
    
    - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
        CGPoint touchLocation = [self convertTouchToNodeSpace: touch];
        CCNode *dialogBox = [self getChildByTag: kDialogTag];
    
        // eat all touches outside of dialog box
        return !CGRectContainsPoint(dialogBox.boundingBox, touchLocation);
    }
    
    - (void) registerWithTouchDispatcher {
        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
    }
    
    @end
    

    Then I can init this using my ModalLayer implementation and then dismiss the modal with a small animation, ie,

    -(void) onButtonPressed:(id) sender
    {
        NSInteger buttonIndex = [sender tag];
        [callback setArgument:&buttonIndex atIndex:2];
        [callback invoke];
    
        id fadeOut    = [CCFadeTo actionWithDuration:0.2f opacity:0];
        id remove = [CCCallFuncND actionWithTarget:self selector:@selector(removeFromParentAndCleanup:) data:(void*)NO];        
    
    
        [self.coverLayer runAction:
         [CCSequence actions:
          fadeOut, remove,
          nil]];
    }
    

    Anyway, I believe I resolved the problem as it seemed to relate to autorelease

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a custom profile page and I need the user to be able
I am creating a custom query builder, when user has created his query he
I'm often creating custom assertion methods for my JUnit tests. eg: public void assertArrays(String[]
I'm creating custom forum software for a site I'm building, which includes 2 tables
I am creating custom cell in my iphone aap and I am also adding
Jython is great for creating custom data structures on need basis, but how to
I have mastered creating custom data types and adding fields with CCK. Then I
I am creating custom membership provider for my asp.net application. I have also created
I m creating custom checkbox and radio button in pure css but they are
I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.