[Mono-dev] Patches for mono-winforms

Steven Boswell II ulatekh at yahoo.com
Sat Jun 16 00:44:11 UTC 2012


Hey, I can copy the stack trace from the call-stack tab in the debugger!  Sweet.  Here it is:

System.Drawing.GDIPlus.CheckStatus (status=System.Drawing.Status.InvalidParameter) in mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs:220
System.Drawing.Graphics.GdipMeasureString (graphics=0xffffffffb4476428, text="Export", font={[Font: Name=DejaVu Sans, Size=8.25, Units=3, GdiCharSet=1, GdiVerticalFont=False]}, layoutRect={{X=0,Y=0,Width=2.147484E+09,Height=2.147484E+09}}, stringFormat=0xffffffffb445b288) in mcs/class/System.Drawing/System.Drawing/Graphics.cs:1950
System.Drawing.Graphics.MeasureString (text="Export", font={[Font: Name=DejaVu Sans, Size=8.25, Units=3, GdiCharSet=1, GdiVerticalFont=False]}, width=2147483647, format={[StringFormat, FormatFlags=0]}) in mcs/class/System.Drawing/System.Drawing/Graphics.cs:1983
System.Windows.Forms.TextRenderer.MeasureTextInternal (dc={System.Drawing.Graphics}, text="Export", font={[Font: Name=DejaVu Sans, Size=8.25, Units=3, GdiCharSet=1, GdiVerticalFont=False]}, proposedSize={{Width=0, Height=0}}, flags=System.Windows.Forms.TextFormatFlags.HidePrefix, useMeasureString=false) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs:304
System.Windows.Forms.TextRenderer.MeasureText (text="Export", font={[Font: Name=DejaVu Sans, Size=8.25, Units=3, GdiCharSet=1, GdiVerticalFont=False]}, proposedSize={{Width=0, Height=0}}, flags=System.Windows.Forms.TextFormatFlags.HidePrefix) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextRenderer.cs:137
System.Windows.Forms.ToolStripItem.CalculateAutoSize () in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs:1507
System.Windows.Forms.ToolStripItem.set_InternalOwner (value=(null)) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs:1898
System.Windows.Forms.ToolStripItemCollection.Remove (value={Export}) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItemCollection.cs:270
System.Windows.Forms.ToolStripItem.Dispose (disposing=false) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs:963
System.Windows.Forms.ToolStripDropDownItem.Dispose (disposing=false) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripDropDownItem.cs:185
System.Windows.Forms.ToolStripMenuItem.Dispose (disposing=false) in mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripMenuItem.cs:222
System.ComponentModel.Component.Finalize () in mcs/class/System/System.ComponentModel/Component.cs:104

Interesting, this is with a different menu item, "Export"...not the one I selected.

I don't know if it matters that 32-bit pointers are getting sign-extended to 64-bit pointers, like graphics=0xffffffffb4476428 in System.Drawing.Graphics.GdipMeasureString(), but that looks suspicious too.

Steven Boswell


________________________________
 From: Steven Boswell II <ulatekh at yahoo.com>
To: "mono-devel-list at lists.ximian.com" <mono-devel-list at lists.ximian.com> 
Sent: Friday, June 15, 2012 5:34 PM
Subject: Re: [Mono-dev] Patches for mono-winforms
 

Enclosed is a new patch, mostly for discussion purposes, since there's no unit test & I don't know how I would write one for this.

Today, after using my application in a particular way, I got it to crash, putting up an "Exception caught" window.  I can't reproduce the problem outside of running it in the MonoDevelop debugger, and there appears to be no way to copy the contents of the stack-trace tab in the exception-caught window (really? how the heck did THIS get missed?), so I can't post the full details.  But it starts at System.ComponentModel.Finalize() with a tool-strip-item (the one I selected seconds before the crash), and ends in System.Drawing.GDIPlus.CheckStatus(Status), where it reports "A null reference or invalid value was found [GDI+ status: InvalidParameter]".

I have no idea why a copy of my menu-item is getting finalized; I certainly didn't make a copy of it.  The good news is, this crash is consistently repeatable, if I just use my application in the same certain order.

Digging through the stack trace, I arrived at System.Windows.Forms.ToolStripItem.set_InternalOwner, where the owner was being set to null, and right afterwards, CalculateAutoSize() was being called.  Why would anyone need to calculate the size of a menu-item that isn't even connected to a menu any more?  So, for me, the bug fix was obvious: check if the owner isn't null before calling CalculateAutoSize().  That's what the enclosed patch does.

With this patch, the bug doesn't reproduce, and the menu-item I selected is still there and doing fine.

Any thoughts on the correctness of this bug fix?  Or how one would write a unit test for it?  Or how to copy the contents of the stack-trace tab in MonoDevelop's exception-caught window?

Steven Boswell

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120615/d036c381/attachment-0001.html>


More information about the Mono-devel-list mailing list