Fix TransformPatch using bitmap from the main thread

This commit is contained in:
Magnus Norddahl 2019-12-29 23:24:08 +01:00
parent 03e50615f6
commit 65fdafafd8
2 changed files with 9 additions and 10 deletions

View file

@ -71,8 +71,7 @@ namespace CodeImp.DoomBuilder.Data
private bool loadfailed;
// GDI bitmap
private Bitmap _bitmap;
protected Bitmap bitmap { get { return _bitmap; } }
private Bitmap bitmap;
private Bitmap previewbitmap;
// Direct3D texture
@ -147,9 +146,9 @@ namespace CodeImp.DoomBuilder.Data
if(!isdisposed)
{
// Clean up
_bitmap?.Dispose();
bitmap?.Dispose();
texture?.Dispose();
_bitmap = null;
bitmap = null;
texture = null;
// Done
@ -200,7 +199,7 @@ namespace CodeImp.DoomBuilder.Data
// Loads the image directly. This is needed by the background loader for some patches.
public Bitmap LocalGetBitmap()
{
// Note: if this turns out to be too slow, do NOT try to make it use GetBitmap or _bitmap.
// Note: if this turns out to be too slow, do NOT try to make it use GetBitmap or bitmap.
// Create a cache for the local background loader thread instead.
LocalLoadResult result = LocalLoadImage();
@ -244,10 +243,10 @@ namespace CodeImp.DoomBuilder.Data
loadfailed = true;
}
_bitmap?.Dispose();
bitmap?.Dispose();
texture?.Dispose();
imagestate = ImageLoadState.Ready;
_bitmap = loadResult.bitmap;
bitmap = loadResult.bitmap;
if (loadResult.uiThreadWork != null)
loadResult.uiThreadWork();

View file

@ -197,7 +197,7 @@ namespace CodeImp.DoomBuilder.Data
if(patchbmp != null)
{
//mxd. Apply transformations from TexturePatch
patchbmp = TransformPatch(p, patchbmp);
patchbmp = TransformPatch(bitmap, p, patchbmp);
// Draw the patch on the texture image
Rectangle tgtrect = new Rectangle(p.X, p.Y, patchbmp.Size.Width, patchbmp.Size.Height);
@ -221,7 +221,7 @@ namespace CodeImp.DoomBuilder.Data
//mxd. Apply transformations from TexturePatch. We don't want to modify the original bitmap here, so make a copy
Bitmap bmp = new Bitmap(img.LocalGetBitmap());
Bitmap patchbmp = TransformPatch(p, bmp);
Bitmap patchbmp = TransformPatch(bitmap, p, bmp);
// Draw the patch on the texture image
Rectangle tgtrect = new Rectangle(p.X, p.Y, patchbmp.Size.Width, patchbmp.Size.Height);
@ -250,7 +250,7 @@ namespace CodeImp.DoomBuilder.Data
}
//mxd
private Bitmap TransformPatch(TexturePatch p, Bitmap patchbmp)
private Bitmap TransformPatch(Bitmap bitmap, TexturePatch p, Bitmap patchbmp)
{
//mxd. Flip
if(p.FlipX || p.FlipY)