Re: Toolbar customizer crashes on Leopard when using menu delegate
Re: Toolbar customizer crashes on Leopard when using menu delegate
- Subject: Re: Toolbar customizer crashes on Leopard when using menu delegate
- From: Peter Ammon <email@hidden>
- Date: Wed, 24 Mar 2010 20:13:28 -0700
Hi Markus,
Yes, this is a known problem on Leopard. The issue is that when NSToolbar shows the customization palette, well, a view can't be in the toolbar and the customization palette simultaneously, so NSToolbar "copies" the popup via NSKeyedArchiver. Unfortunately, NSMenu's encodeWithCoder: method encodes its delegate unconditionally, and if the delegate doesn't implement NSCoding, you get an exception.
In SnowLeopard, NSToolbar was revamped to render the views into images and show the images - not the views - in the customization palette. So NSToolbar in SnowLeopard no longer "copies" views, which is why the problem does not reproduce.
I think the easiest workaround is to implement NSCoding on your NSMenu delegate. The delegate doesn't have to do a very good job encoding itself, because the delegate will not actually be used in the customization palette. In fact, you may be able to get away with implementing replacementObjectForCoder: on your delegate to just return nil.
Hope that helps,
-Peter
On Mar 23, 2010, at 7:02 PM, Markus Spoettl wrote:
> Hello,
>
> I've been running into a strange crash for a toolbar customizer that happens only on Leopard and works fine on Snow Leopard.
>
> My toolbar contains an item hosting a NSPopUpButton which has a menu. That menu contains regular items and a sub-menu which has its delegate assigned to the File's Owner because it's dynamic and needs to be rebuilt each time it is displayed. I have found out that the mere fact the delegate is set causes a crash when the toolbar customizer is created (through "Customize Toolbar…").
>
> Ultimately the whole thing goes down badly inside AppKit (I'm pasting the stack below if someone wants to take a look at it). In the process of digging into this issue I also found that setting the delegate causes the entire nib to be loaded again - probably to resolve the delegate, kind of recursive.
>
> Well, I just thought this would be interesting for the list, since it's working completely fine on Snow Leopard but not on Leopard (Deployment Target of this project is 10.5). Unless of course this was foreseeable in which case I'd like to hear about it.
>
> Regards
> Markus
>
>
> Thread 0 Crashed:
> 0 libobjc.A.dylib 0x9173e699 objc_msgSend + 41
> 1 com.apple.AppKit 0x947cb9fa -[NSMenu encodeWithCoder:] + 444
> 2 com.apple.Foundation 0x9526138d _encodeObject + 621
> 3 com.apple.AppKit 0x947cd08f -[NSMenuItem encodeWithCoder:] + 1563
> 4 com.apple.Foundation 0x9526138d _encodeObject + 621
> 5 com.apple.Foundation 0x952d1bdd -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 541
> 6 com.apple.Foundation 0x952815a7 -[NSArray(NSArray) encodeWithCoder:] + 615
> 7 com.apple.Foundation 0x9526138d _encodeObject + 621
> 8 com.apple.AppKit 0x947cb916 -[NSMenu encodeWithCoder:] + 216
> 9 com.apple.Foundation 0x9526138d _encodeObject + 621
> 10 com.apple.AppKit 0x9481e547 -[NSPopUpButtonCell encodeWithCoder:] + 269
> 11 com.apple.Foundation 0x9526138d _encodeObject + 621
> 12 com.apple.AppKit 0x94503809 -[NSControl encodeWithCoder:] + 349
> 13 com.apple.Foundation 0x9526138d _encodeObject + 621
> 14 com.apple.Foundation 0x95260b08 +[NSKeyedArchiver archivedDataWithRootObject:] + 184
> 15 com.apple.AppKit 0x948f91b9 -[NSToolbarItem _copyOfCustomView] + 47
> 16 com.apple.AppKit 0x948f9278 -[NSToolbarItem copyWithZone:] + 141
> 17 com.apple.CoreFoundation 0x934e2f9a -[NSObject copy] + 42
> 18 com.apple.AppKit 0x9449585a -[NSToolbar _newItemFromItemIdentifier:requireImmediateLoad:willBeInsertedIntoToolbar:] + 306
> 19 com.apple.AppKit 0x94495649 -[NSToolbar _insertNewItemWithItemIdentifier:atIndex:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:] + 86
> 20 com.apple.AppKit 0x944ee904 -[NSToolbar _appendNewItemWithItemIdentifier:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:] + 104
> 21 com.apple.AppKit 0x94497227 -[NSToolbar _setCurrentItemsToItemIdentifiers:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:] + 336
> 22 com.apple.AppKit 0x948f18eb -[NSToolbar _loadInitialItemIdentifiers:requireImmediateLoad:] + 138
> 23 com.apple.AppKit 0x948f7e93 -[NSToolbarConfigPanel _loadDefaultSetImageRep] + 861
> 24 com.apple.AppKit 0x948f6d6b -[NSToolbarConfigPanel _loadData] + 500
> 25 com.apple.AppKit 0x948f674d -[NSToolbarConfigPanel initForToolbar:withWidth:] + 269
> 26 com.apple.AppKit 0x948f1e45 -[NSToolbar _runCustomizationPanel] + 214
> 27 com.apple.AppKit 0x943d7e8f -[NSApplication sendAction:to:from:] + 112
> 28 com.apple.AppKit 0x94486b64 -[NSMenu performActionForItemAtIndex:] + 493
> 29 com.apple.AppKit 0x94486869 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 220
> 30 com.apple.AppKit 0x944634ba AppKitMenuEventHandler + 6608
> 31 com.apple.HIToolbox 0x93e0813d DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1181
> 32 com.apple.HIToolbox 0x93e0757b SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 405
> 33 com.apple.HIToolbox 0x93e23ecc SendEventToEventTarget + 52
> 34 com.apple.HIToolbox 0x93e581e7 SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) + 411
> 35 com.apple.HIToolbox 0x93e7e959 SendMenuCommandWithContextAndModifiers + 59
> 36 com.apple.HIToolbox 0x93e7e914 SendMenuItemSelectedEvent + 134
> 37 com.apple.HIToolbox 0x93e7e82a FinishMenuSelection(MenuData*, MenuData*, MenuResult*, MenuResult*, unsigned long, unsigned long, unsigned long, unsigned char) + 162
> 38 com.apple.HIToolbox 0x93eceb31 PopUpMenuSelectCore(MenuData*, Point, double, Point, unsigned short, unsigned int, Rect const*, unsigned short, unsigned long, Rect const*, Rect const*, __CFString const*, OpaqueMenuRef**, unsigned short*) + 1763
> 39 com.apple.HIToolbox 0x93ece3fb _HandlePopUpMenuSelection7 + 627
> 40 com.apple.AppKit 0x9454f19b _NSPopUpCarbonMenu3 + 3081
> 41 com.apple.AppKit 0x9454e588 _NSPopUpCarbonMenu2 + 155
> 42 com.apple.AppKit 0x9454e4e9 _NSPopUpCarbonMenu1 + 82
> 43 com.apple.AppKit 0x9454e449 -[NSCarbonMenuImpl _popUpContextMenu:withEvent:forView:withFont:] + 237
> 44 com.apple.AppKit 0x9454e282 -[NSMenu _popUpContextMenu:withEvent:forView:withFont:] + 285
> 45 com.apple.AppKit 0x9454e15f -[NSMenu _popUpContextMenu:withEvent:forView:] + 63
> 46 com.apple.AppKit 0x9454e11a -[NSMenu _popUpMenuWithEvent:forView:] + 52
> 47 com.apple.AppKit 0x943d5731 -[NSWindow sendEvent:] + 8511
> 48 com.apple.AppKit 0x943a16a5 -[NSApplication sendEvent:] + 2939
> 49 com.apple.AppKit 0x942fefe7 -[NSApplication run] + 867
> 50 com.apple.AppKit 0x942cc1d8 NSApplicationMain + 574
> 51 com.my.app 0x00007d59 main + 30
> 52 com.my.app 0x000025ae start + 54
> --
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden