unsubscribe from events in core Dispose methods

- closes #4157

Not sure this is the best way to fix the linked issue, but considering this is a hard crash I'd rather fix it somehow than not at all for now.
This commit is contained in:
Morilli 2025-01-02 14:25:56 +01:00
parent b8baf21788
commit b93a995083
8 changed files with 16 additions and 0 deletions

View File

@ -41,6 +41,7 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
public void Dispose()
{
_memoryCallbacks.ActiveChanged -= SetMemoryCallbacks;
if (Context != IntPtr.Zero)
{
LibEmu83.TI83_DestroyContext(Context);

View File

@ -300,5 +300,11 @@ namespace BizHawk.Emulation.Cores.Atari.Jaguar
Marshal.Copy(_buf2352, 0, dst, 2352);
DriveLightOn = true;
}
public override void Dispose()
{
_memoryCallbacks.ActiveChanged -= SetMemoryCallbacks;
base.Dispose();
}
}
}

View File

@ -163,6 +163,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public void Dispose()
{
_memorycallbacks.ActiveChanged -= SetMemoryCallbacks;
if (GambatteState != IntPtr.Zero)
{
LibGambatte.gambatte_destroy(GambatteState);

View File

@ -539,6 +539,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
_glContext = null;
}
_memoryCallbacks.ActiveChanged -= SetMemoryCallbacks;
base.Dispose();
}

View File

@ -156,6 +156,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
public void Dispose()
{
_memorycallbacks.ActiveChanged -= SetMemoryCallbacks;
if (SameboyState != IntPtr.Zero)
{
LibSameboy.sameboy_destroy(SameboyState);

View File

@ -122,6 +122,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
if (!_disposed)
{
_memoryCallbacks.ActiveChanged -= RefreshMemCallbacks;
_elf?.Dispose();
if (_cds != null)

View File

@ -348,6 +348,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
disposed = true;
_memoryCallbacks.ActiveChanged -= RefreshMemCallbacks;
//discs arent bound to shock core instances, but they may be mounted. kill the core instance first to effectively dereference the disc
OctoshockDll.shock_Destroy(psx);
psx = IntPtr.Zero;

View File

@ -52,6 +52,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan
public void Dispose()
{
_inputCallbacks.ActiveChanged -= SetInputCallback;
_memorycallbacks.ActiveChanged -= SetMemoryCallbacks;
if (Core != IntPtr.Zero)
{
BizSwan.bizswan_delete(Core);