+2006-07-06 Sebastien Pouliot <sebastien@ximian.com>
+
+ * 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 <sebastien@ximian.com>
* Image.cs: Made GetThumbnailImage throw OutOfMemoryException when
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);
}
-
}
}
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
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;
if (must_dispose_brush && (brush != null)) {
brush.Dispose ();
+ brush = null;
}
if (nativeObject != IntPtr.Zero) {
Status status = GDIPlus.GdipDeletePen (nativeObject);
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)