c# - Crash when creating MenuItem in code (MonoMac) -
i trying add menu items submenu dynamically during runtime. can add nsmenuitem fine , shows up. if try add event handler, either directly argument constructor, or assigning activated event, crash. menu , submenu created in xcode. add/remove items in 1 specific submenu during runtime.
the crash occurs when submenu drawn. right-click, move mouse on context menu until come item under dynamic submenu resides, , crash!
the crash report quite long here's part think relevant:
thread 1 (process 6706): #0 0x94f73095 in __wait4 () #1 0x9928699a in waitpid$unix2003 () #2 0x004a7d22 in mono_handle_native_sigsegv (signal=11, ctx=0xf6fe0) @ mini-exceptions.c:2344 #3 0x004f7645 in mono_arch_handle_altstack_exception (sigctx=0xf6fe0, fault_addr=0xc8080824, stack_ovf=0) @ exceptions-x86.c:1135 #4 0x00404061 in mono_sigsegv_signal_handler (_dummy=11, info=0xf6fa0, context=0xf6fe0) @ mini.c:6556 #5 <signal handler called> #6 0x98a83a8b in objc_msgsend () #7 0xbfffd920 in ?? () #8 0x9730c963 in -[nscarbonmenuimpl _carbonupdatestatusevent:handlercallref:] () #9 0x973086ee in nsslmmenueventhandler () #10 0x908f79bb in _invokeeventhandlerupp () #11 0x9077f394 in dispatcheventtohandlers () #12 0x9077e780 in sendeventtoeventtargetinternal () #13 0x90792655 in sendeventtoeventtarget () #14 0x908f786a in sendhicommandevent () #15 0x907535f0 in updatehicommandstatuswithcachedevent () #16 0x9077abe2 in hiapplication::eventhandler () #17 0x908f79bb in _invokeeventhandlerupp () #18 0x9077f394 in dispatcheventtohandlers () #19 0x9077e780 in sendeventtoeventtargetinternal () #20 0x90792655 in sendeventtoeventtarget () #21 0x90943054 in sendmenuopening () #22 0x90752dfd in drawthemenu () #23 0x90945779 in opensubmenu () #24 0x90752427 in trackmenucommon () #25 0x9094490d in popupmenuselectcore () #26 0x909441e2 in _handlepopupmenuselection7 () #27 0x97398295 in _nsslmpopupcarbonmenu3 () #28 0x973971b1 in -[nscarbonmenuimpl _popupcontextmenu:withevent:forview:withfont:] () #29 0x97515063 in -[nsmenu _popupcontextmenu:withevent:forview:withfont:] () #30 0x97514f56 in -[nsmenu _popupcontextmenu:withevent:forview:] () #31 0x97515390 in -[nsmenu _popupmenuwithevent:forview:] () #32 0x9771af45 in -[nsview rightmousedown:] () #33 0x973ed635 in -[nscontrol _rightmouseupordown:] () #34 0x973ed69f in -[nscontrol rightmousedown:] () #35 0x971c8af1 in -[nswindow sendevent:] () #36 0x971c390f in -[nsapplication sendevent:] () #37 0x970dd62c in -[nsapplication run] () #38 0x970805f6 in nsapplicationmain () #39 0x06de146b in ?? () #40 0x06de1290 in ?? () #41 0x000befe4 in ?? () #42 0x000bf12f in ?? () #43 0x0040dc05 in mono_jit_runtime_invoke (method=0x9e8c1c, obj=0x0, params=0xbffff468, exc=0x0) @ mini.c:6438 #44 0x005c49ae in mono_runtime_invoke (method=0x9e8c1c, obj=0x0, params=0xbffff468, exc=0x0) @ object.c:2827 #45 0x005c8dc4 in mono_runtime_exec_main (method=0x9e8c1c, args=0xe7f30, exc=0x0) @ object.c:4054 #46 0x005c9135 in mono_runtime_run_main (method=0x9e8c1c, argc=0, argv=0x168d18, exc=0x0) @ object.c:3678 #47 0x00478685 in mono_jit_exec (domain=0x94e00, assembly=0x1833b0, argc=2, argv=0x168d18) @ driver.c:955 #48 0x0047abbf in mono_main (argc=4, argv=0x168d10) @ driver.c:1014 #49 0x0000308f in main ()
i running xamarin studio 4.0.12, mono 3.2.0, xcode 4.6.3, xamarin.mac 1.4.8, os x 10.8.4
i'm hoping our experience shed light. although without code it's rather difficult.
xamarin.mac fantastic job abstracting stuff c# types. 1 thing can't avoided different way each os (and windowing systems in particular) time painting events , resource retention.
in particular cocoa controller style of windowing, there's far greater risk of items expected referenced in memory have been cleaned up, cocoa seems far happier switching windows/controllers , re-hydrating again.
tl;dr
- keep modular reference menuitems - store them in field on controller. otherwise collected.
- before performing repainting, ensure you've no circular references (with cocoa's habit of defining behaviour in delegates belonging objects easier windows)
- removing menu items must end start (remember counts reduce remove)
we have found such mysterious crashes due disappearing controls , or delegates referring objects have reference delegate.
i'm sure more code can more!
cheers ian
Comments
Post a Comment