Author: spouliot
Date: 2006-07-06 08:56:07 -0400 (Thu, 06 Jul 2006)
New Revision: 62313

Modified:
   trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/System.Drawing/Image.cs
   trunk/mcs/class/System.Drawing/System.Drawing/Pen.cs
   trunk/mcs/class/System.Drawing/System.Drawing/SolidBrush.cs
Log:
2006-07-06  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * Image.cs: Ensure we're setting the nativeObject to NULL before 
        throwing any exception while disposing (and avoid possible double
        freeing). Avoid multiple casts in Clone method.
        * Pen.cs: Ensure the internal pen's brush is always disposed 
        correctly. Avoid making a reference to the internal brush.
        * SolidBrush.cs: Avoid setting color when cloning the solid brush
        as the .ctor(IntPtr) always does this job.



Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2006-07-06 
12:52:15 UTC (rev 62312)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2006-07-06 
12:56:07 UTC (rev 62313)
@@ -1,3 +1,13 @@
+2006-07-06  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * Image.cs: Ensure we're setting the nativeObject to NULL before 
+       throwing any exception while disposing (and avoid possible double
+       freeing). Avoid multiple casts in Clone method.
+       * Pen.cs: Ensure the internal pen's brush is always disposed 
+       correctly. Avoid making a reference to the internal brush.
+       * SolidBrush.cs: Avoid setting color when cloning the solid brush
+       as the .ctor(IntPtr) always does this job.
+
 2006-07-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Image.cs: Made GetThumbnailImage throw OutOfMemoryException when

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Image.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Image.cs      2006-07-06 
12:52:15 UTC (rev 62312)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Image.cs      2006-07-06 
12:56:07 UTC (rev 62313)
@@ -758,38 +758,28 @@
                Dispose (false);
        }
 
-       private void DisposeResources ()
-       {
-               Status status = GDIPlus.GdipDisposeImage (nativeObject);
-               GDIPlus.CheckStatus (status);           
-       }
-       
        protected virtual void Dispose (bool disposing)
        {
                if (nativeObject != IntPtr.Zero){
-                       DisposeResources ();
+                       Status status = GDIPlus.GdipDisposeImage (nativeObject);
+                       // set nativeObject to null before throwing an exception
                        nativeObject = IntPtr.Zero;
+                       GDIPlus.CheckStatus (status);           
                }
        }
        
-       public object Clone()
-       {                               
+       public object Clone ()
+       {
+               Bitmap b = (this as Bitmap);
+               if (b == null)
+                       throw new NotImplementedException ("This Image instance 
isn't a Bitmap instance."); 
 
                IntPtr newimage = IntPtr.Zero;
-               
-               if (!(this is Bitmap)) 
-                       throw new NotImplementedException (); 
-               
                Status status = GDIPlus.GdipCloneImage (NativeObject, out 
newimage);                    
                GDIPlus.CheckStatus (status);                   
 
-               if (this is Bitmap){
-                       return new Bitmap (newimage);
-               }
-               
-               throw new NotImplementedException ();           
+               return new Bitmap (newimage);
        }
-
 }
 
 }

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Pen.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Pen.cs        2006-07-06 
12:52:15 UTC (rev 62312)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Pen.cs        2006-07-06 
12:56:07 UTC (rev 62313)
@@ -180,7 +180,14 @@
                                        color = value;
                                        Status status = GDIPlus.GdipSetPenColor 
(nativeObject, value.ToArgb ());
                                        GDIPlus.CheckStatus (status);
+
+                                       /* if required clear existing brush */
+                                       if (must_dispose_brush && (brush != 
null)) {
+                                               brush.Dispose ();
+                                       }
                                        brush = new SolidBrush (color);
+                                       must_dispose_brush = true;
+
                                        status = GDIPlus.GdipSetPenBrushFill 
(nativeObject, brush.nativeObject);
                                        GDIPlus.CheckStatus (status);
                                } else
@@ -471,7 +478,7 @@
                         Status status = GDIPlus.GdipClonePen (nativeObject, 
out ptr);
                        GDIPlus.CheckStatus (status);
                         Pen p = new Pen (ptr);
-                       p.brush = brush;
+                       p.brush = null; // don't reference! managed brush will 
be re-created on demand
                        p.color = color;
                        p.startCap = startCap;
                        p.endCap = endCap;
@@ -493,6 +500,7 @@
 
                        if (must_dispose_brush && (brush != null)) {
                                brush.Dispose ();
+                               brush = null;
                        }
                        if (nativeObject != IntPtr.Zero) {
                                Status status = GDIPlus.GdipDeletePen 
(nativeObject);

Modified: trunk/mcs/class/System.Drawing/System.Drawing/SolidBrush.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/SolidBrush.cs 2006-07-06 
12:52:15 UTC (rev 62312)
+++ trunk/mcs/class/System.Drawing/System.Drawing/SolidBrush.cs 2006-07-06 
12:56:07 UTC (rev 62313)
@@ -78,11 +78,7 @@
                        Status status = GDIPlus.GdipCloneBrush (nativeObject, 
out clonePtr);
                        GDIPlus.CheckStatus (status);
        
-                       SolidBrush clone = new SolidBrush (clonePtr);
-                       clone.color = color;
-                       
-                       return clone;
-                       
+                       return new SolidBrush (clonePtr);
                }
                
                protected override void Dispose (bool disposing)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to