Bug 3128 - Unexpected fatal Exception when painting a double buffered Form
Summary: Unexpected fatal Exception when painting a double buffered Form
Status: RESOLVED INVALID
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-28 12:29 UTC by Fabien GIGANTE
Modified: 2012-01-28 13:15 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Fabien GIGANTE 2012-01-28 12:29:50 UTC
Unfortunately very difficult to reproduce. It happens once in a while, I'm not sure when exactly. But the stack might still help you anyway.

System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Region.Exclude (Rectangle rect) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Region:Exclude (System.Drawing.Rectangle)
  at System.Windows.Forms.Control+DoubleBuffer.End (System.Windows.Forms.PaintEventArgs pe) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.UserControl.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] in <filename unknown>:0
Comment 1 Fabien GIGANTE 2012-01-28 12:51:32 UTC
The only way I can reproduce a similar stack is by calling the Exclude method on an disposed Region :

csharp> Region r = new Region();                
csharp> r.Dispose();
csharp> r.Exclude(Rectangle.Empty); 
System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Region.Exclude (Rectangle rect) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Region:Exclude (System.Drawing.Rectangle)
  at Class7.Host (System.Object& $retval) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00000] in <filename unknown>:0 
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <filename unknown>:0 

But I don't know what could be causing an unexpected disposal of the DoubleBuffer's InvalidRegion in the real life...
Comment 2 Fabien GIGANTE 2012-01-28 13:15:31 UTC
After further investigations on my side, I found a place in my code where I was calling Invalidate in a thread different than the UI thread. Interestingly, it caused no problem to the MS.NET implementation. But that could have been the cause of the problem in mono. I'm using Invoke to Invalidate now instead.

Hoping that this will be enough to fix the problem, I'm closing the bug as Resolved/Invalid for now. Sorry for the inconvenience.