How to handle assertion failure on NSButton lockFocus when using modalWindow on quit?
a button's IBAction
in windowA calls runModalForWindow:windowB
.
windowB becomes key and modal.
windowB has a popUpWindowDatePicker which calls stopModal
upon display, and then popUpWindowDatePicker becomes key, and windowB resigns key and is not modal. no window is modal at this point.
when popUpWindowDatePicker is dismissed, its didResignFirstResponder
method sets a boolean to YES. windowB then becomes key, and windowB's windowController windowDidBecomeKeyNotification
fires, checks the boolean value and if it is YES calls runModalForWindow:self.window
.
now windowB is modal and key. windowA is still open, but not key.
windowB has Okay and Cancel buttons which call:
[NSApp stopModalWithCode:returnCode]
and then orderOut:
and close
on windowB.
if the popUpWindowDatePicker is used, and then any time after tha开发者_如何学Pythont windowB is closed with Okay or Cancel, an Assertion Failure is called involving the Okay or Cancel buttons:
*** Assertion failure in -[NSButton lockFocus], /SourceCache/AppKit/AppKit-1038.29/AppKit.subproj/NSView.m:5237
-[NSButton(0x20021cd60) lockFocus] failed with window=0x20021c0c0, windowNumber=-1, [self isHiddenOrHasHiddenAncestor]=0
if windowB is closed with Okay or Cancel and popUpWindowDatePicker has not been used, there is no assertion failure.
it seems that the sequence runModal-stopModal-runModal-stopModal
on windowB is involved in the failure of lockFocus on the button pressed, but i can't find a way to trace down more than this to solve this problem.
can anyone offer any hints or thoughts?
I had a similar problem when while doing some drawing over an NSTextView with lots of text. What solved this message and other crashes related to 'loosing focus' or calling the 'wrong object' was: Remove the object (and any child it may have) from the Core Animation Layer.
To do this on my NSTextView I unchecked it for any animation easily on the UIbuilder the last tab in the utilities panel corresponding to the Core Animation Layer.
Hope it helps,
I faced similar problem, here my logs:
* Assertion failure in -[NSSecureTextField lockFocus], /SourceCache/AppKit/AppKit-1038.36/AppKit.subproj/NSView.m:5237
[13755:903] unlockFocus called too many time.
[13755:903] unlockFocus called too many time.
[13755:903] -[NSSecureTextField(0x100514b80) lockFocus] failed with window=0x1005298d0, windowNumber=714, [self isHiddenOrHasHiddenAncestor]=1
It seems it is pre-Lion OS X bug, because arter I've upgrade to Lion it has gone away... I guess it occurs after undefined sequence of showModal (NSMenu in my case) and NSWindow orderOut in some point of program execution. After that application continue to work, but became unstable, for examle timer could be stopped, or UI stops to redraw (but still works).
Had a similar issue here. My problem was that my item (a tableView) lost the focus. What I did is to designate my tableView as firstReponder in order that it get focus again.
//...some code...
[self.searchTableView reloadData];
AGAppDelegate *del = [[NSApplication sharedApplication] delegate];
[del.window makeFirstResponder:self.searchTableView];
Hope this will help somebody.
I added a canDraw
method to make sure lockFocus
is available. This solved the problem in my case.
精彩评论