Strange EXC_BAD_ACCESS error

Discussion in 'iOS Programming' started by galt42, Jun 14, 2011.

  1. galt42 macrumors newbie

    Joined:
    Jun 14, 2011
    #1
    I have an application with a single main view that runs essentially all interaction. All of the graphics are painted with graphics functions. For things that need to be painted multiple times, I keep all instances in an NSMutableArray object defined in the view's .h. I just tried to add a third array to this file and it causes a EXC_BAD_ACCESS error before the program loads completely.

    When I have the line:
    NSMutableArray *notifiers;
    in the file, the program bugs out, but it works if that line is commented.

    I have also tried adding this line:
    notifiers = [[NSMutableArray alloc] init];
    in the .m but it does not help.

    The weird thing is that I have two other arrays that work perfectly and they used this exact same definition and initialization. Does anyone know what might cause this error?

    Thanks
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    The only thing wrong with the two isolated lines of code you've show is that they're isolated. No context. No surrounding code. Nothing.

    Try posting the context, such as the complete .h file, and the init or other method where you assign it a value.

    Also consider the possibility of temporarily using a variable name other than 'notifiers'. Maybe 'test_notifiers'. If it still "bugs out", then make sure you're recompiling everything (clean build). If it doesn't bug out, then maybe the problem is with the name 'notifiers', such as you have some inherited variable of that name, or a conflicting property, or something like that.

    Are you using a static library where the malfunctioning class resides? If so, you can't change class @interfaces without recompiling the library.

    In any case, without seeing more code there's no way to diagnose the problem. There's clearly nothing wrong with the two lines of code you posted, so logic suggests the problem lies in the code you haven't posted.
     
  3. galt42 thread starter macrumors newbie

    Joined:
    Jun 14, 2011
    #3
    Sorry, I should have posted code; I was just hoping that this might be something real simple that people miss a lot (and others would recognize).

    Here is the .h:

    Code:
    #import <UIKit/UIKit.h>
    #import <AudioToolbox/AudioToolbox.h>
    @class Ball;
    
    @interface ActiveView : UIView {
        
    	//highscores saved here
    	//highScoreSet *savedHighScores;
    	
    	Ball *ball;
            int speedConstant;
    	
    	NSTimer *ballTimer;
    	NSTimer *drawTimer;
        
    	NSMutableArray *dots;
    	NSMutableArray *shapes;
            NSMutableArray *notifiers;
        
    	//sounds
    	SystemSoundID bounceSound;
    	SystemSoundID tapSound;
    	
    	//keeps track of how long the game has been running
            int level;
    	float interval;
    	float seconds;
            int score;
    	int bounces;
    	
    	/// 0	splash
    	/// 1	main menu
    	/// 2	highscores
    	/// 3	options
    	/// 4	paused
    	/// 5	playing original mode
    	int gameState;
    	
    	int mostRecentShape;
    	
    	int shapeQue[5];	
    }
    
    //- (NSString *)highscorePath;
    
    @end
    
    I have tried other names for the array and nothing has worked.

    Another part of the error said this:
    "Canceling call as the ObjC runtime would deadlock."
    but I left this out initially because it looked like a generic bug-out message. maybe not?

    I also tried cleaning the project and that did not work.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    So basically, if you do nothing else, not initialize 'notifiers' nor assign it any value ever, then this fails:
    Code:
    	NSMutableArray *dots;
    	NSMutableArray *shapes;
            NSMutableArray *notifiers;
    
    but this would work:
    Code:
    	NSMutableArray *dots;
    	NSMutableArray *shapes;
    //        NSMutableArray *notifiers;
    
    Try moving these declarations:
    Code:
    	NSMutableArray *dots;
    	NSMutableArray *shapes;
            NSMutableArray *notifiers;
    
    to here:
    Code:
    	int mostRecentShape;
    	
    	int shapeQue[5];	
    
    	NSMutableArray *dots;
    	NSMutableArray *shapes;
            NSMutableArray *notifiers;
    
    Then do a clean build.


    Also, what is the stack trace in the debugger when the program fails.


    An EXC_BAD_ACCESS is often the result of memory management errors. Try running under Instruments with zombies enabled.
    http://developer.apple.com/library/...mentsUserGuide/AboutTracing/AboutTracing.html

    Also try a Build and Analyze in Xcode, and see what it says.
     
  5. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    EXC_BAD_ACCESS mostly means your project is trying to get to a previous piece of memory which u allocated/inited. And isn't avaible anymore. (hence the bad acces.)

    So with just allocing/initing, you are setting that piece of memory, so u can't get a crash there.
    So with the code you provided, we can't do much, I think the error is somewhere else. otherwise, good luck >.< (hate memory management erros..)
     
  6. galt42 thread starter macrumors newbie

    Joined:
    Jun 14, 2011
    #6
    I tried moving the definitions to the end and that began to run but produced an error the first time one of the arrays was queried. I moved them back and opened instruments. When I ran instruments, it did not appear to crash so I was confused. I went back to the code, made sure it was all uncommented, and ran it. it worked. no clue what happened but either recleaning, moving, retyping, instruments, or something else fixed it. thanks for your help!
     

Share This Page