[Gtk-sharp-list] Access Violations with Mono.Cairo on Windows
m.j.hutchinson at gmail.com
Mon Jan 4 21:52:23 EST 2010
On Wed, Dec 30, 2009 at 4:36 PM, Andy Selvig <ajselvig at gmail.com> wrote:
>> You should probably use a GCHandle to pin the byte:
>> var gch = new GCHandle (imageData, GCHandleType.Pinned);
>> and make sure you gch.Free() when you dispose the surface.
> Thanks, Michael. That was it. Just a small syntax note for others that might
> be reading this, the gc handle is created with:
> gch = GCHandle.Alloc(imageData, GCHandleType.Pinned);
> But, yeah, that fixed it. Works great now.
>> Alternatively, you could modify Mono.Cairo to:
>> * use Marshal.AllocHGlobal to malloc some unmanaged memory, and get an
>> IntPtr to it
>> * use Marshal.Copy to mcpy the byte to the new memory
>> * change the p/invoke signature to use a IntPtr instead of a byte
>> * use Marshal.FreeHGlobal to free the memory when the surface is disposed
> I guess I don't have any fundamental problems with modifying Mono.Cairo, but
> it seems like it's more likely that there's something wrong with me setup. I
> can't be the only one who is using ImageSurfaces on Windows. There must be
> an ImageSurface in MonoDevelop somewhere, right?
> Plus, I'm still troubled by the fact that the API is different for my
> Windows version of Mono.Cairo while the versions seem to be the same. I'll
> have to look further into that.
> But, yes, if this is really what you have to do for image surfaces in
> Mono.Cairo on Windows, then it's a bug and should be fixed IN Mono.Cairo. It
> is unreasonable to expect users of a managed library (even if it's just a
> wrapper to an unmanaged one) to have to manage their own memory.
> If no one else out there can confirm that I'm doing something wrong (using
> an old version of the library, have some sort of version mismatch between
> the managed and unmanaged dll's, etc) then I'll file a bug.
My guess would be that no-one has used ImageSurface on .NET before, or
the people who have run into the issue didn't care to track it down.
It's not a problem on Mono *yet*, because the Boehm GC doesn't move
things, but it will be with SGen. So, yes, worth filing a bug IMO.
More information about the Gtk-sharp-list