Bug 476247

Summary: [Regression] Exception when showing popup menus with MenuPositionFunc
Product: [Mono] Mono: Runtime Reporter: Sanford Armstrong <saarmstrong>
Component: miscAssignee: Mono Bugs <mono-bugs>
Status: VERIFIED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Blocker    
Priority: P1 - Urgent CC: forgotten_vxPDddArjq
Version: 2.4.x   
Target Milestone: 2.4.x   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Simple test case

Description Sanford Armstrong 2009-02-16 17:43:57 UTC
Using svn r127030, gtk-sharp from 2.12 branch r126100.

I get an error message with the following contents whenever I try to right-click in the editor:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper native-to-managed) GtkSharp.MenuPositionFuncWrapper.NativeCallback (intptr,int&,int&,byte,intptr) <0x00037>
at (wrapper managed-to-native) Gtk.Menu.gtk_menu_popup (intptr,intptr,intptr,GtkSharp.MenuPositionFuncNative,intptr,uint,uint) <0x00004>
at Gtk.Menu.Popup (Gtk.Widget,Gtk.Widget,Gtk.MenuPositionFunc,uint,uint) <0x00080>
at MonoDevelop.SourceEditor.ExtensibleTextEditor.ShowPopup () <0x0013d>
at MonoDevelop.SourceEditor.ExtensibleTextEditor.OnPopupMenu (object,Gtk.ButtonPressEventArgs) <0x002c3>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (object,object[],System.Exception&) <0x00004>
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x0009e>

  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000]
Comment 1 Sanford Armstrong 2009-02-17 02:15:51 UTC
Moving to gtk#, because a coworker saw this bug when trying to click on their Tomboy applet with the same revision of the 2.12 branch.

Also, I upped the priority/severity quite a bit, as this is on the stable branch...

Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper native-to-managed) GtkSharp.MenuPositionFuncWrapper.NativeCallback (intptr,int&,int&,byte,intptr) <0x00037>
at (wrapper managed-to-native) Gtk.Menu.gtk_menu_popup (intptr,intptr,intptr,GtkSharp.MenuPositionFuncNative,intptr,uint,uint) <0x00004>
at Gtk.Menu.Popup (Gtk.Widget,Gtk.Widget,Gtk.MenuPositionFunc,uint,uint) [0x00007] in /usr/src/packages/BUILD/gtk-sharp-126100/gtk/generated/Menu.cs:187
at Tomboy.GuiUtils.PopupMenu (Gtk.Menu,Gdk.EventButton,Gtk.MenuPositionFunc) [0x00012] in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Utils.cs:79
at Tomboy.TomboyTrayIcon.ShowMenu (bool) [0x00023] in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Tray.cs:180
at Tomboy.TomboyTrayIcon.OnActivate () [0x00000] in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Tray.cs:160
at Gtk.StatusIcon.activate_cb (intptr) [0x0000d] in /usr/src/packages/BUILD/gtk-sharp-126100/gtk/generated/StatusIcon.cs:262

   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) in /usr/src/packages/BUILD/gtk-sharp-126100/glib/ExceptionManager.cs:line 58
   at Gtk.StatusIcon.activate_cb(IntPtr status_icon) in /usr/src/packages/BUILD/gtk-sharp-126100/gtk/generated/StatusIcon.cs:line 264
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run() in /usr/src/packages/BUILD/gtk-sharp-126100/gtk/generated/AboutDialog.cs:line 1
   at Gnome.Program.Run() in /usr/src/packages/BUILD/gnome-sharp-2.24.0/gnome/generated/About.cs:line 1
   at Tomboy.Application.StartMainLoop() in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Tomboy.cs:line 1
   at Tomboy.Tomboy.StartTrayIcon() in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Tomboy.cs:line 129
   at Tomboy.Tomboy.Main(System.String[] args) in /usr/src/packages/BUILD/tomboy-0.12.1/Tomboy/Tomboy.cs:line 92
ray@ray-laptop:~/.tomboy>
Comment 2 Sanford Armstrong 2009-02-17 02:53:42 UTC
Updating summary. Also, trying to make a small test case, but so far not having much luck, which is troubling.
Comment 3 Sanford Armstrong 2009-02-17 03:06:52 UTC
Created attachment 273148 [details]
Simple test case

Oh, I figured out how to reproduce.  Should have been obvious from the stack trace. You just have to specify a MenuPositionFunc in the Popup call.  Attaching a simple test case based on the sample here:

http://www.mono-project.com/GtkSharpNotificationIcon

Just right-click the StatusIcon and you should experience the crash.  Note that if it does not crash, the context menu will appear in the upper left corner of the screen based on my silly MenuPositionFunc.

It doesn't matter what I build against.  But this test works fine in gtk# 2.12.5 on Mono 2.0.1, and crashes in 2.12.8 (r126100 of gtk-sharp-2-12-branch) on Mono 2.4.
Comment 4 Mike Kestner 2009-02-17 03:42:32 UTC
Is there a specific reason you believe this is a gtk-sharp bug as opposed to a regression in mono between 2.0 and 2.4?  I can't recall any significant changes in callback parameter handling between 2.12.5 and 2.12.8.

I can take a look at this tomorrow, but it would be interesting to see if gtk-sharp-2.12.8 works on mono-2.0 and/or gtk-sharp-2.12.5 fails on 2.4.
Comment 5 Sanford Armstrong 2009-02-17 03:47:53 UTC
(In reply to comment #4)
> Is there a specific reason you believe this is a gtk-sharp bug as opposed to a
> regression in mono between 2.0 and 2.4?  I can't recall any significant changes
> in callback parameter handling between 2.12.5 and 2.12.8.

Because I didn't know any better and was unable to test other combinations.  When in doubt, isn't it standard policy in this world to blame gtk-sharp for everything? :-P

> I can take a look at this tomorrow, but it would be interesting to see if
> gtk-sharp-2.12.8 works on mono-2.0 and/or gtk-sharp-2.12.5 fails on 2.4.

I can easily try the latter combination tomorrow if you haven't already gotten to it by then.
Comment 6 Mike Kestner 2009-02-17 04:21:58 UTC
Heh, just as it's equally standard policy for me to blame mono.  ;-)

I just ran your sample with gtk-sharp-2-12-branch and mono 2.2 and I get a menu item at 0,0 with no crash, FWIW.

It's possible they've fixed something in mono which exposed a latent gtk-sharp bug.  I don't see it in a cursory inspection of that NativeCallback marshaler though.
Comment 7 Sanford Armstrong 2009-02-17 17:15:29 UTC
Okay, with latest mono-2-4 (r127080), I can still reproduce with gtk-sharp 2.12.5 and 2.12.6 from tarball.  I'm going to ask for guidance on how to reassign this bug.
Comment 8 Sanford Armstrong 2009-02-17 17:23:34 UTC
Adding Zoltan to CC list. Any thoughts on how to redirect this bug?
Comment 9 Forgotten User vxPDddArjq 2009-02-17 17:53:53 UTC
Can't repro it using mono HEAD/2.4 branch on amd64.
Comment 10 Sanford Armstrong 2009-02-17 18:57:18 UTC
I can confirm that this is not a problem for me in r125947 of mono-2-4 (~ Feb 5).  Still reproducing in latest version of mono-2-4, though.

I'm on openSUSE 11.0 32-bit.  I'm not sure what else I can do here besides bisecting, which I don't have time for.  I'll see if I can convince a friend to reproduce it.
Comment 11 Sanford Armstrong 2009-02-17 22:54:39 UTC
Zoltan, I assume you tested with my attached test case, and not with the status icon sample on the wiki that I linked to?
Comment 12 Sanford Armstrong 2009-02-17 23:38:48 UTC
I just confirmed this bug with Mono 2.4 Preview 3 on OS X.  You can easily see it if you have Tomboy for Mac running...just left-click on the dock.  It will crash when trying to show the Tomboy menu positioned at the cursor location.
Comment 13 Forgotten User vxPDddArjq 2009-02-17 23:51:50 UTC
Fixed in SVN HEAD/2.4 branch.
Comment 14 Thomas Wiest 2009-02-24 16:14:55 UTC
Moving to runtime since zoltan fixed it.
Comment 15 Thomas Wiest 2009-03-06 23:23:36 UTC
Sandy, can you verify that this is fixed, and if it is, mark the bug verified?

Thanks :)
Comment 16 Thomas Wiest 2009-03-06 23:24:42 UTC
You'll need Mono 2.4rc2 which we'll be releasing early next week (unless you want to build a 2.4 branch build yourself, of course).
Comment 17 Sanford Armstrong 2009-03-07 01:01:47 UTC
Yup, tested this right after Zoltan fixed it and it worked fine. :-) Verifying fixed.
Comment 18 Michael Hutchinson 2009-10-17 23:24:31 UTC
This still happens on Mac PPC - see Bug 547894. Any suggestions?