4

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 that 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?

lulu
  • 669
  • 10
  • 26
  • “The button's method …” Which one? Buttons have a lot of methods, `lockFocus` being just one of them. “… the button does not have `lockFocus` set …” That makes no sense, because `lockFocus` is a verb, not a property. Have you tried breaking on the exception using the debugger? – Peter Hosey Aug 03 '10 at 03:17
  • i've edited my question to reflect that i'm referring to the action method when button is pressed and that lockFocus isn't available on quit. i'll try to break on the exception, and report back. thanks. – lulu Aug 03 '10 at 12:51
  • i've re-written my question to try for more clarity. – lulu Aug 11 '10 at 18:02

4 Answers4

2

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,

user1008139
  • 191
  • 1
  • 2
  • Solved it for me. I was presenting an alert for deleting a tableview item from an ArrayController and got this error. Cheers – GeoffCoope Dec 05 '14 at 17:13
0

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.

toto_tata
  • 14,526
  • 27
  • 108
  • 198
0

I added a canDraw method to make sure lockFocus is available. This solved the problem in my case.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
frank
  • 2,327
  • 1
  • 18
  • 20
0

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).

m8labs
  • 3,671
  • 2
  • 30
  • 32
  • thanks for replying, timur. i'm not using NSSecureTextField. i never found the problem, but i did redesign and the problem resolved without any conclusion on my part. i see we both had isHiddenOrHasHiddenAncestor show up in the log. – lulu Mar 31 '12 at 02:26