Skip to content

Commit

Permalink
Fix NRE when flushing SaveRAM in GambatteLink for some roms
Browse files Browse the repository at this point in the history
fixes d788e60
not clear on the reproduction steps, but it will of course involve a rom
which triggers the "no SaveRAM, return null" in Gambatte
  • Loading branch information
YoshiRulz committed Jun 1, 2024
1 parent a03050d commit 64db1fe
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public byte[] CloneSaveRam()
int len = 0;
for (int i = 0; i < _numCores; i++)
{
linkedBuffers.Add(_linkedCores[i].AsSaveRam().CloneSaveRam()!);
linkedBuffers.Add(_linkedCores[i].AsSaveRam().CloneSaveRam() ?? Array.Empty<byte>());
len += linkedBuffers[i].Length;
}
byte[] ret = new byte[len];
Expand All @@ -56,7 +56,9 @@ public void StoreSaveRam(byte[] data)
int pos = 0;
for (int i = 0; i < _numCores; i++)
{
var b = new byte[_linkedCores[i].AsSaveRam().CloneSaveRam()!.Length];
var toCopy = _linkedCores[i].AsSaveRam().CloneSaveRam(); // wait CloneSaveRam is already a copy, why are we copying it again
if (toCopy is null) continue;
var b = new byte[toCopy.Length];
Buffer.BlockCopy(data, pos, b, 0, b.Length);
pos += b.Length;
_linkedCores[i].AsSaveRam().StoreSaveRam(b);
Expand Down

0 comments on commit 64db1fe

Please sign in to comment.