From f9c85172e4b9e33ab29204470b78a10564083010 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sat, 11 Nov 2023 09:07:38 -0800 Subject: [PATCH] try to fix issues where reloading Citra when recording a movie results a crash due to the temp user folder having active file handles unloading the dll would forcefully evict these file handles. unknown whether Linux does the same with the .so, perhaps it does, perhaps it doesn't. not really any extra harm if it doesn't --- .../Consoles/Nintendo/3DS/Citra.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Citra.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Citra.cs index 5b06c4eb33..43f810f85c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Citra.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Citra.cs @@ -15,13 +15,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS [ServiceNotApplicable(new[] { typeof(IDriveLight), typeof(IRegionable) })] public partial class Citra { - private static readonly LibCitra _core; + private static DynamicLibraryImportResolver _resolver; + private static LibCitra _core; - static Citra() + // This is a hack, largely just so we can forcefully evict file handles Citra keeps open even after shutdown. + // While keeping these file handles open is mostly harmless, this ends up being bad when recording a movie. + // These file handles would be in the user folder, and the user folder must be cleared out when recording a movie! + private static void ResetCitraResolver() { - var resolver = new DynamicLibraryImportResolver( - OSTailoredCode.IsUnixHost ? "libcitra-headless.so" : "citra-headless.dll", hasLimitedLifetime: false); - _core = BizInvoker.GetInvoker(resolver, CallingConventionAdapters.Native); + _resolver?.Dispose(); + _resolver = new(OSTailoredCode.IsUnixHost ? "libcitra-headless.so" : "citra-headless.dll", hasLimitedLifetime: true); + _core = BizInvoker.GetInvoker(_resolver, CallingConventionAdapters.Native); } private static Citra CurrentCore; @@ -48,6 +52,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS } CurrentCore?.Dispose(); + ResetCitraResolver(); + CurrentCore = this; _serviceProvider = new(this);