From a2ddc1b4cdef222565673c9caa13d9eb7139bc95 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:35:03 -0700 Subject: [PATCH] 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) --- src/BizHawk.Client.Common/Api/Classes/GuiApi.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs index 61d527fb3b..dd5f2343c8 100644 --- a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs @@ -273,7 +273,8 @@ namespace BizHawk.Client.Common 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; } @@ -322,7 +323,11 @@ namespace BizHawk.Client.Common var r = Get2DRenderer(surfaceID); r.CompositingMode = _compositingMode; 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), source_x, source_y,