objective-cmalloczombie-processexc-bad-instruction

How to fix Zombie Object throwing 'EXC_BAD_INSTRUCTION' when calling show window


My program visualizes and graphs the currents of simulated neurons and how they interact. When we try to add more than two neurons to be visualized 2/3 times the program crashes with a EXC_BAD_INSTRUCTION error on the line which should show a window which can set the parameters of individual neurons.

I have tried turning on Zombie Objects to get more information but then the program no longer crashes so I can't get any more information. The issue is clearly a Zombie Object problem I just can't figure out how to solve it.

- (IBAction) showParameterSetterWindow:(id)sender
{

    if (parameterSetter == nil)
    {
        ParameterSetter *newParameterSetter = [[ParameterSetter alloc] initWithDefaultWindowNib];
        [self setParameterSetter:newParameterSetter];
    }

    [[self parameterSetter].window orderFront:self]; //Error appears here

} // showSynapseWindow

The error at each location is:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

In the debug window this is printed:

019-08-05 15:15:04.306293-0400 RoboLobsterSimu[1680:175553] Parameter Setter AwakeFromNIB completed
RoboLobsterSimu(1680,0x10013e5c0) malloc: Heap corruption detected, free list is damaged at 0x60001412b1f0
*** Incorrect guard value: 3
RoboLobsterSimu(1680,0x10013e5c0) malloc: *** set a breakpoint in malloc_error_break to debug
RoboLobsterSimu(1680,0x10013e5c0) malloc: Heap corruption detected, free list is damaged at 0x600014128020
*** Incorrect guard value: 13830554455654793216
RoboLobsterSimu(1680,0x10013e5c0) malloc: *** set a breakpoint in malloc_error_break to debug
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

Let me know if you need any more information to solve the problem, thank you! Here are the codes segments I was asked to add. Thank you very much!

Here is initWithDefaultWindowNib

- (id)initWithDefaultWindowNib
{
/*  AnalysisWindowController *awc;
    awc = [super initWithWindowNibName:@"AnalysisWindowController"];
    if (!awc)
        {
        NSLog(@"Warning! Could not load AnalysisWindowController file.\n");
        }
    else
        {
        NSLog(@"AnalysisWindowController Nib Loaded");
        [awc logAnalysisWindowController];
        }
    return awc;
 */
    if (!self){
    self = [super initWithWindowNibName:@"AnalysisWindowController"];
    if (self)
        {
        [self logAnalysisWindowController];
        }
    else
        {
        NSLog(@"Warning! Could not load AnalysisWindowController nib.\n");
        }
    }
    return self;

 }

And it is also called in another file like this:

- (id)initWithDefaultWindowNib
{
  if (!self){
        self = [super initWithWindowNibName:@"ParameterSetter"];
        if (self)
        {
             NSLog(@"Executing InitWithDefaultWIndowNib in Parameter Setter");
        }
        else
        {
            NSLog(@"Warning! Could not load ParameterSetter nib.\n");
        }
    }
    return self;
}

And for setParameterSetter the proffessor said "That’s what the synthesize operator does. it creates a setter and getter. setParameterSetter is created as the setter for ParameterSetter. ParameterSetter is the getter"

Either way, here is parameterSetter:

@property (nonatomic, strong) ParameterSetter          *parameterSetter;
- (ParameterSetter *)parameterSetter
{
    if (parameterSetter == nil)
    {
        ParameterSetter *newParameterSetter = [[ParameterSetter alloc] initWithDefaultWindowNib];
        [self setParameterSetter:newParameterSetter];
    }
    return parameterSetter;
}

Thanks again


Solution

  • If anyone finds this I know this is super unhelpful but I just scrapped the entire parameter setter window and rebuilt it being careful to check for errors at each step and feature added.