Working through the book Cocoa Programming for Mac OS X (third edition) from Aaron Hillegass I am now at Chapter 9, at the end of section Adding Undo to RaiseMan. Hillegass tells you to add two methods to your class MyDocument and then build the app to see that undo/redo is added and working.
But, it isn't working (why else would I be here?). It says:
2012-11-27 19:55:16.231 RaiseMan[293:a0f] HIToolbox: ignoring exception 'undo: NSUndoManager 0x100188a30 is in invalid state, undo was called with too many nested undo groups' that raised inside Carbon event dispatch
(
0 CoreFoundation 0x00007fff88c26784 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff858ddf03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff88c265a7 +[NSException raise:format:arguments:] + 103
3 CoreFoundation 0x00007fff88c26534 +[NSException raise:format:] + 148
4 Foundation 0x00007fff86fd0e17 -[NSUndoManager undo] + 239
5 AppKit 0x00007fff8976eeda -[NSApplication sendAction:to:from:] + 95
6 AppKit 0x00007fff8979346a -[NSMenuItem _corePerformAction] + 365
7 AppKit 0x00007fff897931d4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
8 AppKit 0x00007fff89a18cf4 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
9 AppKit 0x00007fff898ca9e9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
10 AppKit 0x00007fff8977599c NSSLMMenuEventHandler + 321
11 HIToolbox 0x00007fff83d937f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
12 HIToolbox 0x00007fff83d92d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
13 HIToolbox 0x00007fff83db0a81 SendEventToEventTarget + 45
14 HIToolbox 0x00007fff83ddfc35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
15 HIToolbox 0x00007fff83e0ca0a SendMenuCommandWithContextAndModifiers + 56
16 HIToolbox 0x00007fff83e0c9c2 SendMenuItemSelectedEvent + 101
17 HIToolbox 0x00007fff83e0c8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
18 HIToolbox 0x00007fff83dedc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467
19 HIToolbox 0x00007fff83ded37c _HandleMenuSelection2 + 453
20 AppKit 0x00007fff89646851 _NSHandleCarbonMenuEvent + 236
21 AppKit 0x00007fff8961a362 _DPSNextEvent + 1908
22 AppKit 0x00007fff89619801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
23 AppKit 0x00007fff895df68f -[NSApplication run] + 395
24 AppKit 0x00007fff895d83b0 NSApplicationMain + 364
25 RaiseMan 0x000000010000160a main + 33
26 RaiseMan 0x0000000100001218 start + 52
27 ??? 0x0000000000000001 0x0 + 1
)
in the console when I click undo or press cmd+z.
I found solutions for this online, but they are all about 'UndoGroups' or something similar.
I know that the exception is about nested undo groups, but I don't use them (AFAIK), I don't even know what they are.
I don't know what else information I should give, so please ask in the comments for code fragments etc.
For future readers:
Hillegass tells you to add 2 methods: -insertObject:inEmployeesAtIndex: and -removeObjectFromEmployeesAtIndex:. In the second method you have to do:
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p inEmployeesAtIndex:index];
But I did:
NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:p atIndex:index]; //atIndex: instead of inEmployeesAtIndex:
Related
So I was messing around with the Document Based Application, and I'm trying get the save file to work. I have a file format save to .lgre and whenever I hit save, I'll select location, and then nothing happens except that I get this in that console. Can someone tell me whats going wrong?
0 CoreFoundation 0x00007fff8c64b64c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8e9ca6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8c64b4fd +[NSException raise:format:] + 205
3 Ligre UI 0x00000001000011b1 -[Document dataOfType:error:] + 129
4 AppKit 0x00007fff933d8fcf -[NSDocument writeToURL:ofType:error:] + 861
5 AppKit 0x00007fff933dbf03 -[NSDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:] + 494
6 AppKit 0x00007fff933dae6b -[NSDocument _writeSafelyToURL:ofType:forSaveOperation:forceTemporaryDirectory:error:] + 850
7 AppKit 0x00007fff933dbb93 -[NSDocument _writeSafelyToURL:ofType:forSaveOperation:error:] + 28
8 AppKit 0x00007fff933dbd01 -[NSDocument writeSafelyToURL:ofType:forSaveOperation:error:] + 357
9 AppKit 0x00007fff933e8fc5 __66-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_22307 + 240
10 AppKit 0x00007fff933e8ec6 __66-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke2304 + 365
11 AppKit 0x00007fff933e72e6 __66-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke2176 + 1587
12 AppKit 0x00007fff93426882 __62-[NSDocumentController(NSInternal) _onMainThreadInvokeWorker:]_block_invoke1881 + 175
13 CoreFoundation 0x00007fff8c56954c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
14 CoreFoundation 0x00007fff8c55b655 __CFRunLoopDoBlocks + 341
15 CoreFoundation 0x00007fff8c55b196 __CFRunLoopRun + 1814
16 CoreFoundation 0x00007fff8c55a838 CFRunLoopRunSpecific + 296
17 HIToolbox 0x00007fff9421243f RunCurrentEventLoopInMode + 235
18 HIToolbox 0x00007fff942121ba ReceiveNextEventCommon + 431
19 HIToolbox 0x00007fff94211ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
20 AppKit 0x00007fff92fbe6d1 _DPSNextEvent + 964
21 AppKit 0x00007fff92fbde80 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
22 AppKit 0x00007fff92fb1e23 -[NSApplication run] + 594
23 AppKit 0x00007fff92f9d2d4 NSApplicationMain + 1832
24 Ligre UI 0x0000000100001302 main + 34
25 libdyld.dylib 0x00007fff8cea45c9 start + 1
26 ??? 0x0000000000000003 0x0 + 3
)
Did you override dataOfType or one of the writeToURL methods?
See the discussion here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocument_Class/index.html#//apple_ref/occ/instm/NSDocument/dataOfType:error:
I've been trying to find out what's wrong with this piece of code: I have an NSTextView which string I want to update when the user clicks in one one my table views. For now on, I'm just trying to get it to display the string "Notes".
Any idea on what I am doing wrong ? I looked into beginEditing: and endEditing: without any success.
//
// MyAppDelegate.h
#property IBOutlet NSTextView* stickyNoteContainer;
//
// MyAppDelegate.m
-(void)updateOverview{
[stickyNoteContainer setString:#"Notes"];
}
Here's the stack :
MyApp[1176:303] *** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range or index out of bounds
2013-09-23 15:04:12.084 MyApp[1176:303] (
0 CoreFoundation 0x00007fff917eaf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff95bb7d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff917ead8a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff917ead14 +[NSException raise:format:] + 116
4 Foundation 0x00007fff955afbc5 -[NSString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:] + 160
5 Foundation 0x00007fff955afb1e -[NSString getParagraphStart:end:contentsEnd:forRange:] + 40
6 AppKit 0x00007fff8e5c1cd7 _NSFastFillAllLayoutHolesForGlyphRange + 1040
7 AppKit 0x00007fff8eb31bb4 -[NSTextView(NSPrivate) _ensureLayoutCompleteForVisibleRectWithExtensionFactor:minimumExtensionDistance:repetitions:] + 563
8 AppKit 0x00007fff8eb2d13c -[NSTextView(NSPrivate) _ensureLayoutCompleteForVisibleRectWithExtension:] + 45
9 AppKit 0x00007fff8e6b9650 -[NSTextView setNeedsDisplayInRect:avoidAdditionalLayout:] + 2078
10 AppKit 0x00007fff8e6bf1c1 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 5690
11 AppKit 0x00007fff8e5b0110 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2678
12 AppKit 0x00007fff8e96b948 _enableTextViewResizing + 209
13 AppKit 0x00007fff8e5a8454 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 582
14 AppKit 0x00007fff8e5a81f6 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 155
15 AppKit 0x00007fff8e681133 -[NSTextStorage processEditing] + 205
16 AppKit 0x00007fff8e681cab -[NSTextStorage endEditing] + 81
17 MyApp 0x0000000100007938 -[MyAppDelegate updateOverview] + 1624
18 MyApp 0x0000000100008751 -[MyAppDelegate tableViewSelectionDidChange:] + 177
19 Foundation 0x00007fff95550d0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
20 CoreFoundation 0x00007fff917937ba _CFXNotificationPost + 2634
21 Foundation 0x00007fff9553cfc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
22 AppKit 0x00007fff8e674049 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
23 AppKit 0x00007fff8e64ab0a -[NSTableView _enableSelectionPostingAndPost] + 425
24 AppKit 0x00007fff8e670e58 -[NSTableView mouseDown:] + 5030
25 AppKit 0x00007fff8e5d6c98 -[NSWindow sendEvent:] + 6306
26 AppKit 0x00007fff8e5703a5 -[NSApplication sendEvent:] + 5593
27 AppKit 0x00007fff8e506a0e -[NSApplication run] + 555
28 AppKit 0x00007fff8e782eac NSApplicationMain + 867
29 MyApp 0x0000000100002002 main + 34
30 MyApp 0x0000000100001fd4 start + 52
)
EDIT : I realized the piece of code actually runs twice without any exception at the end of the program initialization, during my - (void)applicationDidFinishLaunching: routine. After that, any triggering will be faulty. What does this suggest ?
EDIT 2 : Put aside the fact using insertText: appends instead of replacing, I get a very similar exception when trying :
MyApp[1919:303] *** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range or index out of bounds
2013-09-23 15:34:03.956 MyApp[1919:303] (
0 CoreFoundation 0x00007fff917eaf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff95bb7d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff917ead8a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff917ead14 +[NSException raise:format:] + 116
4 Foundation 0x00007fff955afbc5 -[NSString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:] + 160
5 Foundation 0x00007fff955afb1e -[NSString getParagraphStart:end:contentsEnd:forRange:] + 40
6 AppKit 0x00007fff8e5c1cd7 _NSFastFillAllLayoutHolesForGlyphRange + 1040
7 AppKit 0x00007fff8eb31bb4 -[NSTextView(NSPrivate) _ensureLayoutCompleteForVisibleRectWithExtensionFactor:minimumExtensionDistance:repetitions:] + 563
8 AppKit 0x00007fff8eb2d13c -[NSTextView(NSPrivate) _ensureLayoutCompleteForVisibleRectWithExtension:] + 45
9 AppKit 0x00007fff8e6b9650 -[NSTextView setNeedsDisplayInRect:avoidAdditionalLayout:] + 2078
10 AppKit 0x00007fff8e6bf1c1 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 5690
11 AppKit 0x00007fff8e5b0110 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2678
12 AppKit 0x00007fff8e96b948 _enableTextViewResizing + 209
13 AppKit 0x00007fff8e5a8454 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 582
14 AppKit 0x00007fff8e5a81f6 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 155
15 AppKit 0x00007fff8e681133 -[NSTextStorage processEditing] + 205
16 AppKit 0x00007fff8e681cab -[NSTextStorage endEditing] + 81
17 AppKit 0x00007fff8eb0620f -[NSTextView insertText:replacementRange:] + 2013
18 AppKit 0x00007fff8eb05a25 -[NSTextView insertText:] + 320
19 MyApp 0x00000001000078c1 -[MyAppDelegate updateOverview] + 1569
20 MyApp 0x0000000100008751 -[MyAppDelegate tableViewSelectionDidChange:] + 177
21 Foundation 0x00007fff95550d0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
22 CoreFoundation 0x00007fff917937ba _CFXNotificationPost + 2634
23 Foundation 0x00007fff9553cfc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
24 AppKit 0x00007fff8e674049 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
25 AppKit 0x00007fff8e64ab0a -[NSTableView _enableSelectionPostingAndPost] + 425
26 AppKit 0x00007fff8e670e58 -[NSTableView mouseDown:] + 5030
27 AppKit 0x00007fff8e5d6c98 -[NSWindow sendEvent:] + 6306
28 AppKit 0x00007fff8e5703a5 -[NSApplication sendEvent:] + 5593
29 AppKit 0x00007fff8e506a0e -[NSApplication run] + 555
30 AppKit 0x00007fff8e782eac NSApplicationMain + 867
31 MyApp 0x0000000100001fc2 main + 34
32 MyApp 0x0000000100001f94 start + 52
)
It turned out I was modifying the stringValue of a NSTextView while it was calling textDidEndEditing:, which resulted in a mismatched string count and a Range or index out of bounds exception thrown when this wrong count was being used inside NSTextView inner methods.
I just bypassed the problem by using an ivar #property BOOL canModifyTextViewString which would be set accordingly inside methods where modifying the string is unsafe/not possible.
NSTextView doesn't have setString as a class method
-(void)updateOverview{
[stickyNoteContainer insertText:#"Notes"];
}
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTextView/insertText:
I'm trying to change the current selection of a NSTableView with the following code:
[self.modesTable selectRowIndexes:indexSet byExtendingSelection:NO];
and I'm getting the following error:
-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
I'm not using any dictionary at all. Anybody knows where this might come from?
Here's the stack trace:
2012-04-03 18:14:00.598 TurnMode[7130:403] An uncaught exception was raised
2012-04-03 18:14:00.599 TurnMode[7130:403] -[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
2012-04-03 18:14:00.603 TurnMode[7130:403] (
0 CoreFoundation 0x00007fff8ac44fc6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8644cd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ac44dfa +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff8ac44d84 +[NSException raise:format:] + 116
4 CoreFoundation 0x00007fff8ac01ec0 -[__NSCFDictionary setObject:forKey:] + 96
5 TurnMode 0x0000000100009722 -[FRRMode saveObject:named:] + 210
6 TurnMode 0x0000000100008f20 -[FRRMode saveToUserDefaults] + 192
7 TurnMode 0x000000010000701d -[FRRPreferencesController tableViewSelectionDidChange:] + 125
8 Foundation 0x00007fff877b7d32 __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
9 CoreFoundation 0x00007fff8abedaaa _CFXNotificationPost + 2634
10 Foundation 0x00007fff877a3fe7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
11 AppKit 0x00007fff8bcd51d9 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
12 AppKit 0x00007fff8bcabbfe -[NSTableView _enableSelectionPostingAndPost] + 425
13 AppKit 0x00007fff8bcd4045 -[NSTableView _doSelectIndexes:byExtendingSelection:indexType:funnelThroughSingleIndexVersion:] + 2915
14 TurnMode 0x0000000100006662 -[FRRPreferencesController syncViewWithTempModel] + 914
15 TurnMode 0x0000000100006c76 -[FRRPreferencesController showPreferencesView:] + 438
16 CoreFoundation 0x00007fff8ac3475d -[NSObject performSelector:withObject:] + 61
17 AppKit 0x00007fff8bc6ecb2 -[NSApplication sendAction:to:from:] + 139
18 AppKit 0x00007fff8bd5bfe7 -[NSMenuItem _corePerformAction] + 399
19 AppKit 0x00007fff8bd5bd1e -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 125
20 AppKit 0x00007fff8bff9dd4 -[NSMenu _internalPerformActionForItemAtIndex:] + 38
21 AppKit 0x00007fff8be8a3a9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 138
22 AppKit 0x00007fff8bcd5b4b NSSLMMenuEventHandler + 339
23 HIToolbox 0x00007fff8d6f4294 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1263
24 HIToolbox 0x00007fff8d6f38a0 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 446
25 HIToolbox 0x00007fff8d70a677 SendEventToEventTarget + 76
26 HIToolbox 0x00007fff8d7506c1 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 398
27 HIToolbox 0x00007fff8d837c59 SendMenuCommandWithContextAndModifiers + 56
28 HIToolbox 0x00007fff8d87e73d SendMenuItemSelectedEvent + 253
29 HIToolbox 0x00007fff8d7497bb _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 101
30 HIToolbox 0x00007fff8d877175 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1660
31 HIToolbox 0x00007fff8d877434 _HandlePopUpMenuSelection7 + 621
32 AppKit 0x00007fff8be8d075 _NSSLMPopUpCarbonMenu3 + 3860
33 AppKit 0x00007fff8c2386b6 _NSPopUpCarbonMenu3 + 39
34 AppKit 0x00007fff8be8b1da -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 322
35 AppKit 0x00007fff8c0eb8da +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 673
36 AppKit 0x00007fff8c0ebb85 -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 147
37 AppKit 0x00007fff8bc6cbde -[NSControl mouseDown:] + 786
38 AppKit 0x00007fff8bc376e0 -[NSWindow sendEvent:] + 6306
39 AppKit 0x00007fff8c0ec598 -[NSStatusBarWindow sendEvent:] + 66
40 AppKit 0x00007fff8bbd016d -[NSApplication sendEvent:] + 5593
41 AppKit 0x00007fff8bb661f2 -[NSApplication run] + 555
42 AppKit 0x00007fff8bde4b88 NSApplicationMain + 867
43 TurnMode 0x0000000100001ab2 main + 34
44 TurnMode 0x0000000100001a84 start + 52
)
The exception is definitely caused by calling -[NSDictionary setObject:forKey:] in -[FRRMode saveObject:named:].
If you are indeed not using any dictionaries in this method, you should still look for setObject:forKey:. If you over-release an object, its memory address may be occupied by an NSDictionary which obviously does not respond to the selector.
It appears that -[FRRPreferencesController syncViewWithTempModel] is your method which is calling [self.modesTable selectRowIndexes:indexSet byExtendingSelection:NO]. Then, the table view dutifully changes its selection.
It also appears that your FRRPreferencesController object is an observer of the notification posted by the table view when its selection changes. That, in turn, calls -[FRRMode saveToUserDefaults] which calls -[FRRMode saveObject:named:] and that is trying to mutate an immutable dictionary.
From the name saveToUserDefaults, I wonder if you're grabbing a dictionary-typed value from NSUserDefaults and then trying to mutate it. NSUserDefaults does not hold or return mutable collections, even if you pass a mutable collection into its -setObject:forKey:. When you later retrieve it, you get an immutable copy.
In my subclass of NSWindowController, [self window] is null.
In my nib file THERE IS a link between the File's Owner (my subclass) and the Window View.
Why do I get this error ?
It stopped to work when I refactored the File Owner's class (the subclass of NSWindowController). I've updated it in the nib so I don't understand why it stopped to work.
Crashing line:
session = [NSApp beginModalSessionForWindow:[self window]];
2011-10-25 12:27:14.377 MyApp [13161:b0f] *** Assertion failure in -[CBApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /SourceCache/AppKit/AppKit-1138.23/AppKit.subproj/NSApplication.m:3861
2011-10-25 12:27:14.377 MyApp[13161:b0f] An uncaught exception was raised
2011-10-25 12:27:14.378 MyApp[13161:b0f] Modal session requires modal window
2011-10-25 12:27:14.380 MyApp[13161:b0f] (
0 CoreFoundation 0x92e01d87 __raiseError + 231
1 libobjc.A.dylib 0x9317e149 objc_exception_throw + 155
2 CoreFoundation 0x92d69619 +[NSException raise:format:arguments:] + 137
3 Foundation 0x9c41c36f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x958a987d -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] + 725
5 AppKit 0x958a1973 -[NSApplication beginModalSessionForWindow:] + 72
6 MyApp 0x00042ca3 -[CBWindowController showModal:] + 131
7 MyApp 0x00023c46 -[CBDocument showLinkWindow:shouldLinkAndUpdate:selectedOnly:] + 1174
8 MyApp 0x00023cb1 -[CBDocument linkAllRootItems:] + 81
9 MyApp 0x0002a9b4 -[CBApplicationDelegate linkAllItems:] + 100
10 CoreFoundation 0x92d57091 -[NSObject performSelector:withObject:] + 65
11 AppKit 0x956e1cb3 -[NSApplication sendAction:to:from:] + 232
12 AppKit 0x957d5caf -[NSMenuItem _corePerformAction] + 536
13 AppKit 0x957d592c -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 171
14 AppKit 0x957d4fb5 -[NSMenu _performActionWithHighlightingForItemAtIndex:sendAccessibilityNotification:] + 79
15 AppKit 0x95aaddab -[NSMenu performActionForItemAtIndex:] + 65
16 AppKit 0x95aaddde -[NSMenu _internalPerformActionForItemAtIndex:] + 45
17 AppKit 0x95ab200f -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 106
18 AppKit 0x9591ba10 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 172
19 AppKit 0x9574a916 NSSLMMenuEventHandler + 452
20 HIToolbox 0x9b175920 _Z22_InvokeEventHandlerUPPP25OpaqueEventHandlerCallRefP14OpaqueEventRefPvPFlS0_S2_S3_E + 36
21 HIToolbox 0x9aff1803 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1602
22 HIToolbox 0x9aff0c80 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 482
23 HIToolbox 0x9b005aa9 SendEventToEventTarget + 76
24 HIToolbox 0x9b175de4 _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 482
25 HIToolbox 0x9b175e4e SendMenuCommandWithContextAndModifiers + 70
26 HIToolbox 0x9b1e0697 SendMenuItemSelectedEvent + 275
27 HIToolbox 0x9b0423f9 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 129
28 HIToolbox 0x9b1d1574 _ZL14MenuSelectCoreP8MenuData5PointdmPP13OpaqueMenuRefPt + 608
29 HIToolbox 0x9b03a0b2 _HandleMenuSelection2 + 636
30 HIToolbox 0x9b039e31 _HandleMenuSelection + 53
31 AppKit 0x95646356 _NSHandleCarbonMenuEvent + 302
32 AppKit 0x955d662e _DPSNextEvent + 2196
33 AppKit 0x955d58ab -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
34 AppKit 0x955d1c22 -[NSApplication run] + 911
35 AppKit 0x9586618a NSApplicationMain + 1054
36 MyApp 0x000042f4 main + 36
37 MyApp 0x00002e06 start + 54
How the NSWindowController is created:
CBWindowController *windowController = [[subClass alloc] init];
[windowController setRanAsModal:YES];
[windowController setDelegate:self];
[windowController setRootDocument:[NSApp mainWindowDocument]];
[windowController loadWindow];
[windowController centerOnMainWindow:sender];
[self window] must point to a valid window object. From your comments, it is not.
You must check and re-connect the window outlet, or, if there is no such outlet, ensure that a valid object is held in that variable.
Automatic refactoring doesn't appear to catch everything - so a search of your project for the old name would seem to be a worthwhile exercise after refactoring to prevent issues like this in the future.
I'm willing to bet you are initializing it wrong. You need to specifiy the NIB name when you initialize your class, like so:
CBWindowController *windowController =
[[subClass alloc] initWithWindowNibName:#"MyWindow" owner:nil];
Better yet, just fold that code into your window controller's init method.
Edit: Also, do NOT call loadWindow on your object, that method is called automatically when the window is accessed, as mentioned in the documentation.
I have a WebView in a NSWindow and when I close the window and open it again the app crashes ;(
The window is called by a menu item button.
Here is the output:
2011-10-22 15:55:32.440 Textis[17176:903] -[__NSCFType mainFrame]: unrecognized selector sent to instance 0x100514e90
2011-10-22 15:55:32.544 Textis[17176:903] HIToolbox: ignoring exception '-[__NSCFType mainFrame]: unrecognized selector sent to instance 0x100514e90' that raised inside Carbon event dispatch
(
0 CoreFoundation 0x00007fff838b17b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff8127af03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff8390b110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff8388391f ___forwarding___ + 751
4 CoreFoundation 0x00007fff8387fa68 _CF_forwarding_prep_0 + 232
5 Textis 0x0000000100003722 -[Share tweet:] + 210
6 AppKit 0x00007fff84b3eeda -[NSApplication sendAction:to:from:] + 95
7 AppKit 0x00007fff84b6346a -[NSMenuItem _corePerformAction] + 365
8 AppKit 0x00007fff84b631d4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121
9 AppKit 0x00007fff84de8cf4 -[NSMenu _internalPerformActionForItemAtIndex:] + 35
10 AppKit 0x00007fff84c9a9e9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136
11 AppKit 0x00007fff84b4599c NSSLMMenuEventHandler + 321
12 HIToolbox 0x00007fff8665d7f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002
13 HIToolbox 0x00007fff8665cd46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395
14 HIToolbox 0x00007fff8667aa81 SendEventToEventTarget + 45
15 HIToolbox 0x00007fff866a9c35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387
16 HIToolbox 0x00007fff866d6a0a SendMenuCommandWithContextAndModifiers + 56
17 HIToolbox 0x00007fff866d69c2 SendMenuItemSelectedEvent + 101
18 HIToolbox 0x00007fff866d68d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150
19 HIToolbox 0x00007fff867dfa69 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1618
20 HIToolbox 0x00007fff867dfdc2 _HandlePopUpMenuSelection7 + 665
21 AppKit 0x00007fff84c9799b _NSSLMPopUpCarbonMenu3 + 3720
22 AppKit 0x00007fff84ec76f9 -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 162
23 AppKit 0x00007fff84bc92f5 -[NSControl mouseDown:] + 624
24 AppKit 0x00007fff84ae33a7 -[NSWindow sendEvent:] + 5409
25 AppKit 0x00007fff84ec8498 -[NSStatusBarWindow sendEvent:] + 68
26 AppKit 0x00007fff84a18afa -[NSApplication sendEvent:] + 4719
27 AppKit 0x00007fff849af6de -[NSApplication run] + 474
28 AppKit 0x00007fff849a83b0 NSApplicationMain + 364
29 Textis 0x00000001000010c2 main + 34
30 Textis 0x0000000100001094 start + 52
31 ??? 0x0000000000000001 0x0 + 1
)
mainFrame is a method on WebView
so
2011-10-22 15:55:32.544 Textis[17176:903] HIToolbox: ignoring exception '-[__NSCFType mainFrame]: unrecognized selector sent to instance 0x100514e90' that raised inside Carbon event dispatch
points to your WebView being released either by you explicitly or implicitly by the OS when the window is shut. You are hitting a dead pointer.
Not sure how you are setting up your window but you are probably assuming that the original WebView is still a valid object at a reopen.
Have a look in that direction.