0

I am trying to render the Awesomium headless browser in a BackgroundWorker.

However, when i try to copy the buffer using CopyTo, i get an AccessViolationException saying that i am trying to access protected memory. This is my first time using the System.Drawing namespace.

Here is my code:

            RenderBuffer b = browser.Render();
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(size.Width, size.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Imaging.BitmapData bmd = bmp.LockBits(new System.Drawing.Rectangle(0, 0,size.Width, size.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            b.CopyTo(bmd.Scan0, bmd.Stride, 4, false, false);
            bmp.UnlockBits(bmd);
            System.IO.MemoryStream dat = new System.IO.MemoryStream(bmp.Width * bmp.Height * 4);
            bmp.Save(dat, System.Drawing.Imaging.ImageFormat.Png);
            page = Texture2D.FromStream(Game.GraphicsDevice, dat);
            bmp.Dispose();

Thanks in advance!

UDXS
  • 40
  • 1
  • 6
  • Maybe the bitmap size is incorrect and Awesomium is overflowing the buffer? – Gusman Feb 26 '16 at 22:01
  • I have them set to the same XNA rectangle. I heard that this exception must have happened with unmanaged code (Awesomium) – UDXS Feb 26 '16 at 22:18
  • Check the Width and Height of the RenderBuffer to see if it matches the size you used. – Gusman Feb 26 '16 at 22:20
  • Yes, it is in the unmanaged code, and it's because the CopyTo is calling the native Awesomium functions, and the most probable cause of that exception is a buffer overflow, because that the check of the size – Gusman Feb 26 '16 at 22:21
  • I'll check the rest of the code to make sure the browser is initializing right – UDXS Feb 26 '16 at 22:22

0 Answers0