Francesco
Francesco

Reputation: 1848

NSPopover crashes when window closes

Long story short:

If I put a NSTableView with highlight style set to SourceList inside a NSPopover, my app crashes when I close the window containing the popover.

EDIT: I can replicate this issue on a new project. https://dl.dropboxusercontent.com/u/7968745/PopoverFail.zip

Long story:

I have a very strange issue. Currently debugging with NSZombie seems to lead the problem to a NSPopover, but I'm not completely sure because I cannot replicate it in a new project.

I have a NSWindow and its controller which creates a NSViewController and its view (everything created with IB). In this view there is a button which opens a popover. This popover has a simple NSTableView with style set to SourceList. The popover is transient.

If I open the popover, and directly close the window everything is ok. If I open the popover, change focus to a textfield in the window (so that the popover closes) and then close the window, the app crashes.

Enabling zombie I see the following log

*** -[NSPopoverFrame _subviewGeometryChanged:]: message sent to deallocated instance 0x1005ce3d0

If I profile with NSZombie this is the stack:

Instrument stack

I can replicate the issue every time. I've change now the style of the table view to regular and the crash does not happen anymore (but I lost the translucent effect on yosemite.

I don't know what can be the problem, and if it is really the table view / popover combination

EDIT: More information: I'm using ARC. The issue arises at the deallocation of the window. I removed all the code of the application except the one needed to open the window. The crash happens also in this case.

EDIT: I can replicate this issue on a new project. https://dl.dropboxusercontent.com/u/7968745/PopoverFail.zip

I'll also open a bug report to Apple

Upvotes: 3

Views: 774

Answers (2)

Demitri
Demitri

Reputation: 14039

I’m not able to reproduce the error with your project, but as I was having a similar issue I thought I’d post a reply (and possible solution). If a popup window is open and you close the window it's attached to, you need to clean things up in the view’s dealloc method. This is what I did:

- (void)dealloc
{
    if (self.thePopover.shown) {
        [self.thePopover close]; // forces the popover to close w/o consulting the delegate
        self.thePopover.delegate = nil;
        self.thePopover = nil;
    }
}

This might be hitting the problem with a sledgehammer (why would I need to set the delegate to nil if close won’t call it?), but it solved the crashing problem for me.

Upvotes: 0

A O
A O

Reputation: 5698

Based off your comment reply; this is an issue with your NSPopover being deallocated before subviewGeometryChanged gets called. I don't know when it does get called, but when it does it is expecting your NSPopover to exist.

A good analogy that is commonly used balloons. A strong reference is a person holding onto a balloon, while also pointing at it. A weak reference is a person just pointing at a balloon being held by somebody else. So if the weak reference is pointing at this balloon, and the person holding it lets go, then the weak reference will be pointing at nil.

Try changing your NSPopover property to be of type (strong) and see if that fixes it for you

Upvotes: 0

Related Questions