On Mar 25, 2010, at 9:10 AM, Markus Spoettl wrote: > Hi Peter, > > On Mar 24, 2010, at 11:13 PM, Peter Ammon wrote: >> 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. > > > Thanks a lot for the detailed explanation. Something else must be playing > into this because my delegate is an NSWindowController subclass which already > conforms to the NSCoding protocol. A second instance actually gets created > during the customizer setup, but it's dealloc'd before the crash happens.
Delegates aren't retained by the menu, so when NSToolbar copies the menu, it will create a new instance of your delegate which will then soon be deallocated because nothing retains it. If the delegate isn't removed from the menu, then the menu will crash when it tries to talk to the delegate. So another fix would be to remove your delegate from the menu in the -dealloc method. -Peter _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com