Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

misee

macrumors member
Original poster
Jul 4, 2010
65
0
Hi

I'm having a little trouble with a sheet. I have a document based application, that should show a sheet right after opening a document (the sheet is attached to the document window). I have subclassed NSWindowController (as the documents window controller) and ran the sheet from the windowDidLoad. Now my problem is, that the sheet is not displayed correctly. It is shown as if it were a normal window, except that it does not have a title bar. This is the log I get:

Tue Jan 4 21:18:11 Michael.local [17772] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Tue Jan 4 21:18:11 Michael.local [17772] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Tue Jan 4 21:18:11 Michael.local [17772] <Error>: kCGErrorIllegalArgument: CGSCopyWindowProperty
Tue Jan 4 21:18:11 Michael.local [17772] <Error>: kCGErrorIllegalArgument: CGSGetWindowProperty
Tue Jan 4 21:18:11 Michael.local [17772] <Error>: kCGErrorIllegalArgument: windowGroup: error getting ordering group property
These are the methods that were called (I got these from setting the CGErrorBreakpoint):
Code:
#0	0x7fff847e847f in CGErrorBreakpoint
#1	0x7fff84872a5a in CGSGlobalErrorv
#2	0x7fff8468e5ad in _CGSFindSharedWindow
#3	0x7fff8467cd0f in _CGSWindowByID
#4	0x7fff846adc26 in CGSCopyWindowProperty
#5	0x7fff846adad9 in CGSGetWindowProperty
#6	0x7fff846adaa6 in windowGroup
#7	0x7fff846ad5c8 in CGSOrderWindowListWithGroups
#8	0x7fff846ad3f7 in CGSOrderWindowWithGroup
#9	0x7fff8478a93c in CGSOrderPanelIfActive
#10	0x7fff83952f65 in -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:]
#11	0x7fff83b94103 in -[NSApplication _orderFrontModalWindow:relativeToWindow:]
#12	0x7fff83b93b6b in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:]
#13	0x1000078f7 in -[DocumentGroup _runSheetForOpeningUnopenedFiles] at DocumentGroup.m:304
I "solved" the problem by waiting 0.01 seconds before opening the sheet. I used NSTimer to do this.

I'm running Mac OS X 10.6.5.

I got the same error when I ran a sheet from awakeFromNib in a clean project which I created only to find out if this bug is due to my project settings or something similar.

So my question: Am I doing something wrong? Are there any better workarounds than using a timer?
 
Last edited:
As you've found out it you can't successfully run a modal sheet (or dialog) from within the windowDidLoad because the window loading sequence is not yet complete.

Instead of using a timer, try this code inside windowDidLoad.

Code:
[self performSelectorOnMainThread:@selector(_runSheetForOpeningUnopenedFiles)
                       withObject:nil 
                    waitUntilDone:NO];

This will schedule _runSheetForOpeningUnopenedFiles to be called outside of the window loading sequence.
 
Wow, thanks! I guess I didn't think far enough (or maybe too far?). I'm really glad I can dump that ugly NSTimer solution.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.