Debugger: PPU Viewer - Fixed rare crashes when exporting to PNG (caused by trying to use previously pinned memory after it is no longer pinned and might have been moved by the GC)

This commit is contained in:
Sour 2018-12-09 13:02:06 -05:00
parent 70ad89a05a
commit 031f320d44
2 changed files with 13 additions and 2 deletions

View file

@ -143,7 +143,11 @@ namespace Mesen.GUI.Debugger.Controls
g.DrawImageUnscaled(source, 0, 0);
}
_originalChrBanks[i] = source;
Bitmap originalImg = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using(Graphics g = Graphics.FromImage(originalImg)) {
g.DrawImage(source, 0, 0);
}
_originalChrBanks[i] = originalImg;
_chrBanks[i] = target;
Bitmap chrBankImage = new Bitmap(256, 256);

View file

@ -68,7 +68,14 @@ namespace Mesen.GUI.Debugger.Controls
GCHandle handle = GCHandle.Alloc(_spritePixelData, GCHandleType.Pinned);
try {
_imgSprites = new Bitmap(64, 128, 4*64, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap source = new Bitmap(64, 128, 4*64, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject());
Bitmap sprites = new Bitmap(64, 128, PixelFormat.Format32bppArgb);
using(Graphics g = Graphics.FromImage(_imgSprites)) {
g.DrawImage(source, 0, 0);
}
_imgSprites = sprites;
using(Graphics g = Graphics.FromImage(picSprites.Image)) {
g.Clear(Color.FromArgb(64, 64, 64));
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;