EXC_BAD_ACCESS (code=1, address=0x0) when runModalForWindow

15,556

Solution 1

the best way to debug EXC_BAD_ACCESS errors is to use NSZombies.

Check out this video for an explanation :

http://youtu.be/LQtPr8bkB3g

NSZombie keeps all your objects in memory when you are trying to release an object that has already been released, so you get closer to finding your bug. As @Mark H said, it is a memory management issue.

Also you could put an NSLog in your dealloc method to have a better idea of what is getting deallocated when at runtime.

Solution 2

That error will be thrown when the object doesn't exist in memory. I'd start looking for memory management issues. The first would be to make sure you are releasing the ChooseProceduresWindowController after using it.

Share:
15,556
Radu Paise
Author by

Radu Paise

Updated on June 05, 2022

Comments

  • Radu Paise
    Radu Paise almost 2 years

    I have a window and a window controller which opens when the user clicks a button. Sometimes I get EXC_BAD_ACCESS(code=1, address=0x0).

    0x7fff6f2a59e0:  movq   (%rax), %rdi
    

    Here is the code:

        ChooseProceduresWindowController *chooseProceduresWindowController = [[ChooseProceduresWindowController alloc] initWithWindowNibName:@"ChooseProceduresWindow"];
        [NSApp runModalForWindow:[chooseProceduresWindowController window]];
    

    The error appears then runModalForWindow: is called. I don't get this error every time, but I couldn't find a pattern.

    Thanks

  • Radu Paise
    Radu Paise almost 12 years
    I get the error before releasing, when I try to open it in modal.
  • Mark
    Mark almost 12 years
    Do you open it multiple times and does it ever error out on the first try?
  • Radu Paise
    Radu Paise almost 12 years
    Yes, I open it multiple times, and No, I didn't get the error on the first try.
  • Mark
    Mark almost 12 years
    What does the code look like for releasing the allocated memory? Does it always get called?
  • Radu Paise
    Radu Paise almost 12 years
    [chooseProceduresWindowController release]; - just after the runForModal:
  • Mark
    Mark almost 12 years
    I might be misunderstanding, but it seems like you are releasing the memory immediately after allocating it. Release the memory when you are done with the modal window.
  • Nico
    Nico almost 11 years
    @MarkH: runModalForWindow: blocks until the modal event loop has been stopped or aborted (hopefully by the questioner's code in response to an action).
  • Tim
    Tim over 10 years
    I ran into this error when I tried releasing an alertView twice. (Still a noob at Objective-C)
  • Nicolas Miari
    Nicolas Miari about 10 years
    Sometimes an object in the middle of being deallocated throws a "does not respond to selector" exception. And sometimes EXC_BAD_ACCESS is due to reading outside of the bounds of an array (seg fault), if I'm not wrong... But NSZombies is a good measure to start.