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 6584479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:32:31+00:00 2026-05-25T16:32:31+00:00

I am coding Objective-C using the Cocos2D framework, and I have a singleton used

  • 0

I am coding Objective-C using the Cocos2D framework, and I have a singleton used for multiple purposes. One new purposes is to get and set character’s “states” which are strings. I’ve recently made an NSDictionary for this purpose, but I have issues with the program freezing up when a method inside the singleton is called.

Here’s the singleton code. I’m just leaving in the character state stuff:

.h

@interface ExGlobal : NSObject { 

    NSArray *charStates_keys;
    NSArray *charStates_objects;

    NSMutableDictionary *charStates;
} 

@property(nonatomic, retain) NSMutableDictionary *charStates;

+(ExGlobal*)sharedSingleton; 

- (NSString *)charState:(NSString *)charName;
- (void)set_charState:(NSString *)value forCharName:(NSString *)charName;

@end 

.m

#import "ExGlobal.h" 

@implementation ExGlobal 

@synthesize charStates;

static ExGlobal* _sharedSingleton = nil; 

+(ExGlobal*)sharedSingleton { 
    @synchronized([ExGlobal class]) {

        if (!_sharedSingleton) { 
            [[self alloc] init]; 
        } 

        return _sharedSingleton; 
    } 

    return nil; 
} 

+(id)alloc { 
    @synchronized([ExGlobal class]) { 

        NSAssert(_sharedSingleton == nil, @"Attempted to allocate a second instance of a singleton."); 
        _sharedSingleton = [super alloc]; 
        return _sharedSingleton; 

    } 

    return nil; 
} 

-(id)init { 
    self = [super init]; 
    if (self != nil) { 
        // initialize stuff here 

        exitName = @"ruinsSkyMid";

        sceneChangeKind = @"reborn";

        charStates = [[NSMutableDictionary alloc] init];

        charStates_keys = [NSArray arrayWithObjects:@"Feathers", @"Hummus", nil];

        charStates_objects = [NSArray arrayWithObjects:@"at wall", @"with Feathers", nil];

        charStates = [NSMutableDictionary dictionaryWithObjects:charStates_objects forKeys:charStates_keys];

    } 
    return self; 
} 


- (NSString *)charState:(NSString *)charName{

    NSString *value = [charStates objectForKey:charName];

    return value;

}

- (void)set_charState:(NSString *)charState forCharName:(NSString *)charName{

    [charStates setObject:charState forKey:charName];

}

- (void)dealloc {
    //I know it doesn't get called, but just in case
    [charStates release];

    [super dealloc];
}


@end 

It’s unclear to me what exactly the issue is when it freezes. When this happens, all I get in the console is:

    Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.5 (8L1)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Previous frame inner to this frame (gdb could not unwind past this frame)
Previous frame inner to this frame (gdb could not unwind past this frame)

Which I’m sure doesn’t help finding the issue. I found if I redefine charStates_keys, charStates_objects and charStates inside both the charState and set_charState methods, it seems to work without freezing, except set_charState does not change the state.

  • 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-05-25T16:32:32+00:00Added an answer on May 25, 2026 at 4:32 pm

    It isn’t freezing, it is crashing. Hence the EXC_BAD_ACCESS. It looks like your Xcode installation is borked, too, as the two messages following should not happen.

    Note that methods should not have _s in the name; not a cause of the problem, but a comment on following convention.

    You aren’t retaining charStates and that is likely the cause of the crash.

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

Sidebar

Related Questions

I am new to the objective c coding in iPhone. i am using below
I've started using Project Euler to improve my objective-c coding and have worked through
I'm still pretty new to Objective-C coding (as evidenced by this question) and I
So new to objective-c and iphone/ipad development. Trying to get my feet wet with
I have done one iPhone app in Objective-C. When I want to link a
Is there any pdf which tells about coding guidelines in objective C. For Example...
In Objective-C on Apple there is something called Key-Value Coding that allows you to
I've been coding my way through Steve Kochan's Programming in Objective-C 2.0 book. I'm
Are there any generally-accepted coding standards (naming, casting etc) that apply specifically to iPhone/Cocoa/Objective-C?
Coming from a C++ background, one thing that confuses me about Objective C is

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.