[Mono-bugs] [Bug 76991][Nor] New - Dispose() of graphics causing Unhandled Exception

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Dec 13 22:34:13 EST 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by vik at econz.co.nz.

http://bugzilla.ximian.com/show_bug.cgi?id=76991

--- shadow/76991	2005-12-13 22:34:13.000000000 -0500
+++ shadow/76991.tmp.12911	2005-12-13 22:34:13.000000000 -0500
@@ -0,0 +1,205 @@
+Bug#: 76991
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: Linux vik.econz.co.nz 2.6.14-2-686 Debian
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Windows.Forms
+AssignedTo: peter at novonyx.com                            
+ReportedBy: vik at econz.co.nz               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Dispose() of graphics causing Unhandled Exception
+
+Description of Problem:
+
+Running a simple application on mono 1.1.10-1 that sets
+System.Windows.Forms.PaintEventHandler causes an Unhandled Exception when
+the graphics area is disposed of.
+
+Steps to reproduce the problem:
+1. Compile graphicalSample.cs so:
+
+mcs graphicalSample.cs  /r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+2. Run with "mono graphicalSample.exe"
+
+3. Repeat without the g.Dispose() and watch it work. The presence of the
+code between the 
+
+	Graphics g = e.Graphics;
+        ...
+        g.Dispose();
+
+does not seem to affect the outcome.
+
+
+
+Actual Results:
+
+vik at vik:~/src/mono_apps/ArrayTest$ mono graphicalSample.exe Mono
+System.Windows.Forms Assembly [Revision: 51965; built: 2005/10/20 3:34:45]
+Keyboard: United States keyboard layout (phantom key version)
+Gtk colorscheme read
+
+vik at vik:~/src/mono_apps/ArrayTest$ mcs graphicalSample.cs 
+/r:System.Windows.Forms.dll /r:System.Drawing.dll
+
+vik at vik:~/src/mono_apps/ArrayTest$ mono graphicalSample.exe Mono
+System.Windows.Forms Assembly [Revision: 51965; built: 2005/10/20 3:34:45]
+Keyboard: United States keyboard layout (phantom key version)
+Gtk colorscheme read
+
+Unhandled Exception: System.ArgumentException: Invalid Parameter. A null
+reference or invalid value was found.
+in <0x00084> System.Drawing.GDIPlus:CheckStatus (Status status)
+in <0x0001e> System.Drawing.Graphics:Flush (FlushIntention intention)
+in <0x0000c> System.Drawing.Graphics:Flush ()
+in (wrapper remoting-invoke-with-check) System.Drawing.Graphics:Flush ()
+in <0x0002c> System.Windows.Forms.XplatUIX11:PaintEventEnd (IntPtr handle,
+Boolean client)
+in <0x0001a> System.Windows.Forms.XplatUI:PaintEventEnd (IntPtr handle,
+Boolean client)
+in <0x00517> System.Windows.Forms.Control:WndProc
+(System.Windows.Forms.Message m)
+in <0x0000d> System.Windows.Forms.ScrollableControl:WndProc
+(System.Windows.Forms.Message m)
+in <0x0000d> System.Windows.Forms.ContainerControl:WndProc
+(System.Windows.Forms.Message m)
+in <0x008be> System.Windows.Forms.Form:WndProc (System.Windows.Forms.Message m)
+in <0x00014> System.Windows.Forms.Control+ControlNativeWindow:WndProc
+(System.Windows.Forms.Message m)
+in <0x0011e> System.Windows.Forms.NativeWindow:WndProc (IntPtr hWnd, Msg
+msg, IntPtr wParam, IntPtr lParam)
+in <0x00016> System.Windows.Forms.XplatUIX11:DispatchMessage
+(System.Windows.Forms.MSG msg)
+in <0x00015> System.Windows.Forms.XplatUI:DispatchMessage
+(System.Windows.Forms.MSG msg)
+in <0x00222> System.Windows.Forms.Application:Run ()
+in <0x000a4> System.Windows.Forms.Application:Run
+(System.Windows.Forms.ApplicationContext context)
+in <0x0002e> System.Windows.Forms.Application:Run
+(System.Windows.Forms.Form mainForm)
+in <0x0001f> WindowsApplication1.Form1:Main ()
+
+Expected Results:
+
+Elipse, rectangle and text displayed on red background.
+
+
+How often does this happen? 
+
+Every time.
+
+Additional Information:
+
+Code taken from half way down:
+
+http://bdn.borland.com/article/0,1410,32073,00.html
+
+Vik :v)
+
+------------------------------------------------------
+Code (graphicalSample.cs):
+
+using System;
+using System.Drawing;
+using System.Collections;
+using System.ComponentModel;
+using System.Windows.Forms;
+//using System.Data;
+
+namespace WindowsApplication1
+{
+	/// <summary>
+	/// Summary description for Form1.
+	/// </summary>
+	public class Form1 : System.Windows.Forms.Form
+	{
+		/// <summary>
+		/// Required designer variable.
+		/// </summary>
+		private System.ComponentModel.Container components = null;
+
+		public Form1()
+		{
+			//
+			// Required for Windows Form Designer support
+			//
+			InitializeComponent();
+
+			//
+			// TODO: Add any constructor code after InitializeComponent call
+			//
+		}
+
+		/// <summary>
+		/// Clean up any resources being used.
+		/// </summary>
+		protected override void Dispose( bool disposing )
+		{
+			if( disposing )
+			{
+				if (components != null) 
+				{
+					components.Dispose();
+				}
+			}
+			base.Dispose( disposing );
+		}
+
+		#region Windows Form Designer generated code
+		/// <summary>
+		/// Required method for Designer support - do not modify
+		/// the contents of this method with the code editor.
+		/// </summary>
+		private void InitializeComponent()
+		{
+			// 
+			// Form1
+			// 
+			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+			this.BackColor = System.Drawing.Color.Red;
+			this.ClientSize = new System.Drawing.Size(380, 150);
+			this.Name = "Form1";
+			this.Text = "Form1";
+			this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
+
+		}
+		#endregion
+
+		/// <summary>
+		/// The main entry point for the application.
+		/// </summary>
+		[STAThread]
+		static void Main() 
+		{
+			Application.Run(new Form1());
+		}
+
+		private void Form1_Paint(object sender,
+System.Windows.Forms.PaintEventArgs e)
+		{
+			Graphics g = e.Graphics;
+			
+			Rectangle rect = new Rectangle(20, 30, 100, 50); 
+			g.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 255, 0)), rect);
+			rect.X += 160;                     
+			g.FillEllipse(new SolidBrush(Color.FromArgb(255, 255, 255, 255)), rect);
+			SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(255, 255, 255,
+0));
+			g.DrawString("Built in Linux, runs on Windows", 
+			    new Font("Verdana", 14), semiTransBrush,
+			    new RectangleF(20, 100, 375, 100) );
+			
+		
+			// Dispose (causes crash on Mono)
+			g.Dispose();		
+		}
+}
+}


More information about the mono-bugs mailing list