[Mono-list] System.AccessViolationException just under Win32

Massimo Perga massimo.perga at gmail.com
Sun Aug 20 07:35:50 EDT 2006

Hello all,
  I'm working on the Win32 support for the GIMP# project - a framework which
allows developers to write GIMP plugins using C#; in particular, I'm taking
care of bug-fixing all the issues related to unit tests (run with NUnit).
I'm facing this exception:

"*System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt*"

The piece of code involved is the "get" block of the following method:

    public byte[] this[int row, int col]
   int bpp = (int) pr.bpp;
   IntPtr dest = (IntPtr) ((int) pr.data + (row - Y) * Rowstride +
      (col - X) * bpp);
   Marshal.Copy(value, 0, dest, value.Length);

   int bpp = (int) pr.bpp;
   IntPtr src = (IntPtr) ((int) pr.data + (row - Y) * Rowstride +
     (col - X) * bpp);
   Marshal.Copy(src, _dummy, 0, bpp);

   return _dummy;

After several investigations,it seems that the problem is related to "src"
variable and the "Marshal.Copy" invocation. The attribute "pr.data" has type
"IntPtr" but the block of memory referenced by it is allocated directly by
GIMP (in an unmanaged way), so I can't use the method Marshal.AllocHGlobal .

It works fine with Linux, but under Win32 it raises that exception.

Thanks in advance for your support,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20060820/702441bd/attachment-0001.html 

More information about the Mono-list mailing list