[Mono-bugs] [Bug 76152][Maj] New - Error when Bitmap.LockBits called on locked clone

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Sep 19 18:38:13 EDT 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 bill.seddon at lyquidity.com.

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

--- shadow/76152	2005-09-19 18:38:13.000000000 -0400
+++ shadow/76152.tmp.11984	2005-09-19 18:38:13.000000000 -0400
@@ -0,0 +1,139 @@
+Bug#: 76152
+Product: Mono: Class Libraries
+Version: 1.0
+OS: other
+OS Details: CentOS 4.1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: libgdiplus
+AssignedTo: jordi at ximian.com                            
+ReportedBy: bill.seddon at lyquidity.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Error when Bitmap.LockBits called on locked clone
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+
+If Bitmap.LockBits is called on a clone of a bitmap that is locked, an 
+error will be generated.  The same program run under .NET 1.1 or Mono on 
+Windows works fine.  The code to clone a bitmap in Bitmap.cs looks OK so 
+I think this indicates a problem (or at least a functional difference) in 
+function GdipCloneImage of libgdiplus.
+
+Steps to reproduce the problem:
+
+Compile the following program.  Assuming it is saved as "test.cs" then 
+the commands to compile and run will be:
+
+mcs test.cs /r:System.Drawing.dll
+mono test.exe
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+public class TestLockBits : IDisposable
+{
+
+	int _bmpWidth = 150, _bmpHeight = 150;
+	System.Drawing.Bitmap _bmp = null;
+	byte[] _bmpBytes = null;
+	private System.Drawing.Imaging.BitmapData	_bmpBitmapData;	
+	
+
+	public static void Main(string[] args)
+	{
+		TestLockBits t = new TestLockBits();
+		t.SubTest();
+	}
+
+	public TestLockBits()
+	{
+		_bmp = new System.Drawing.Bitmap(_bmpHeight, _bmpWidth);
+
+		_bmpBytes = new Byte[_bmpWidth*_bmpHeight*4];
+		Console.WriteLine("Initial lock...");
+		_bmpBitmapData =  _bmp.LockBits(new 
+System.Drawing.Rectangle(0,0,_bmpWidth,_bmpHeight), 
+System.Drawing.Imaging.ImageLockMode.ReadWrite, 
+System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+		Console.WriteLine("Marshalling...");
+		System.Runtime.InteropServices.Marshal.Copy
+(_bmpBitmapData.Scan0,_bmpBytes,0,_bmpWidth*_bmpHeight*4);
+	}
+
+	private void SubTest()
+	{
+
+		using(System.Drawing.Bitmap tmp = (System.Drawing.Bitmap)
+_bmp.Clone())
+		{
+			Console.WriteLine("Locking...");
+			System.Drawing.Imaging.BitmapData tmpData =  
+tmp.LockBits(new System.Drawing.Rectangle(0,0,_bmpWidth,_bmpHeight), 
+System.Drawing.Imaging.ImageLockMode.ReadWrite, 
+System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+
+			byte[] tmpBytes = new Byte
+[_bmpWidth*_bmpHeight*4];
+
+			Console.WriteLine("Marshalling...");
+			System.Runtime.InteropServices.Marshal.Copy
+(tmpData.Scan0,tmpBytes,0,_bmpWidth*_bmpHeight*4);
+
+			//copy data back
+			Console.WriteLine("Copying back...");
+			System.Runtime.InteropServices.Marshal.Copy
+(tmpBytes, 0, tmpData.Scan0, _bmpWidth*_bmpHeight*4);
+
+			Console.WriteLine("Unlocking...");
+			tmp.UnlockBits(tmpData);
+		}
+
+	}
+
+	#region IDisposable Members
+
+	void System.IDisposable.Dispose()
+	{
+		Console.WriteLine("Final unlock...");
+		try { _bmp.UnlockBits(_bmpBitmapData); } 
+		catch {}
+	}
+
+	#endregion
+}
+
+Actual Results:
+
+Initial lock...
+Marshalling...
+Locking...
+in <0x00084> System.Drawing.GDIPlus:CheckStatus (Status status)
+in <0x000b1> System.Drawing.Bitmap:LockBits (Rectangle rect, 
+ImageLockMode flags, PixelFormat format)
+in (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:LockBits 
+(System.Drawing.Rectangle,System.Drawing.Imaging.ImageLockMode,System.Draw
+ing.Imaging.PixelFormat)
+in <0x00109> TestLockBits:SubTest ()
+
+Expected Results:
+
+Initial lock...
+Marshalling...
+Locking...
+Marshalling...
+Copying back...
+Unlocking...
+
+How often does this happen? 
+
+Every time.
+
+Additional Information:


More information about the mono-bugs mailing list