make sure to dispose Image from Image.FromFile

these hold a lock until they get disposed (which without explicit disposing is just waiting on the finalizer to do it)
This commit is contained in:
CasualPokePlayer 2024-09-19 22:35:03 -07:00
parent 073ce5fa4d
commit a2ddc1b4cd
1 changed files with 7 additions and 2 deletions

View File

@ -273,7 +273,8 @@ namespace BizHawk.Client.Common
if (!_imageCache.TryGetValue(path, out var img)) if (!_imageCache.TryGetValue(path, out var img))
{ {
img = new(Image.FromFile(path)); using var file = Image.FromFile(path);
img = new(file);
if (cache) _imageCache[path] = img; if (cache) _imageCache[path] = img;
} }
@ -322,7 +323,11 @@ namespace BizHawk.Client.Common
var r = Get2DRenderer(surfaceID); var r = Get2DRenderer(surfaceID);
r.CompositingMode = _compositingMode; r.CompositingMode = _compositingMode;
r.DrawImage( r.DrawImage(
_imageCache.GetValueOrPut(path, static i => new(Image.FromFile(i))), _imageCache.GetValueOrPut(path, static i =>
{
using var file = Image.FromFile(i);
return new(file);
}),
new Rectangle(dest_x, dest_y, dest_width ?? source_width, dest_height ?? source_height), new Rectangle(dest_x, dest_y, dest_width ?? source_width, dest_height ?? source_height),
source_x, source_x,
source_y, source_y,