fix crash in MGBA memory callbacks due to GC of temporarily marshaled delegate (by keeping an instance referenced in a member, as usual)

This commit is contained in:
zeromus 2020-04-03 18:42:22 -04:00
parent be8db22d6c
commit 6b462630e0
1 changed files with 5 additions and 2 deletions

View File

@ -56,7 +56,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
}
else
{
LibmGBA.BizSetMemCallback(container.Call);
LibmGBA.BizSetMemCallback(container.CallDelegate);
container.ID = LibmGBA.BizSetWatchpoint(_mgba.Core, callback.Address.Value, container.WatchPointType);
}
@ -106,6 +106,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
public CallbackContainer(IMemoryCallback callBack)
{
Callback = callBack;
CallDelegate = Call;
}
public IMemoryCallback Callback { get; }
@ -130,7 +131,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
}
}
public void Call(uint addr, LibmGBA.mWatchpointType type, uint oldValue, uint newValue)
public LibmGBA.MemCallback CallDelegate;
void Call(uint addr, LibmGBA.mWatchpointType type, uint oldValue, uint newValue)
{
Callback.Callback?.Invoke(addr, newValue, 0);
}