3

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

Francesco
  • 1,840
  • 19
  • 24

2 Answers2

0

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

A O
  • 5,516
  • 3
  • 33
  • 68
  • Usually if an object is created in the `nib`, is the responsibility of the `nib` to keep a strong reference to it. And to avoid cycles the `IBOutlet` is usually `weak`. Anyway I tried to change it to `strong` and it did not solve the problem. I'm starting to thing the problem is somewhere else... – Francesco Feb 15 '15 at 10:09
  • Ah sorry, I wasn't thinking fully you're right. Can you try implementing the `NSWindowDelegate` method, `windowWillClose`-- then setting a break point in there and seeing what the value of your NSPopover is? – A O Feb 16 '15 at 00:41
  • Yes. Now with the test project is very easy :) . The popover is not nil at that point. It seems like some notifications or methods are not properly handled by the popover at deallocation. – Francesco Feb 16 '15 at 07:56
  • Cool ^^ do you know why they aren't being handled properly? I'm just curious now – A O Feb 16 '15 at 15:00
  • This is why I opened this question :) :p I hope Apple will answer to my bug report – Francesco Feb 16 '15 at 18:02
  • Any update on that from Apple or from you? I hit a similar problem and have trouble finding a solution to this. Thank you for the connection to Source-List highlighting, it didn't spring tot my mind, based on the Zombie result. – Jacob Gorban Mar 23 '15 at 21:43
  • Try setting NSTableView's datasource delegate to be nil when the popover is dealloced? – A O Mar 23 '15 at 22:51
  • @JacobGorban still nothing from Apple. – Francesco Mar 24 '15 at 12:46
0

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.

Demitri
  • 13,134
  • 4
  • 40
  • 41
  • I've just tried again I am not able to verify it anymore. Maybe they fixed the problem (without acknowledge it on the bug report). I'm curious if there is anybody with OS X 10.2 (and Xcode 6.1.1 and related OS X SDK) to test it. – Francesco Jul 10 '15 at 07:49