From 73efec2a0202d87830ae3b616b8496edee4ee9a3 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 30 Jan 2022 19:21:27 -0800 Subject: [PATCH] GBA Video: Fix rare crash in modes 3-5 --- CHANGES | 1 + src/gba/renderers/software-bg.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index ea90d3629..09ed6f0cb 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,7 @@ Emulation fixes: - GBA Video: Fix OpenGL rendering on M1 Macs - GBA Video: Ignore horizontally off-screen sprite timing (fixes mgba.io/i/2391) - GBA Video: Fix Hblank timing (fixes mgba.io/i/2131, mgba.io/i/2310) + - GBA Video: Fix rare crash in modes 3-5 Other fixes: - Core: Don't attempt to restore rewind diffs past start of rewind - FFmpeg: Fix crash when encoding audio with some containers diff --git a/src/gba/renderers/software-bg.c b/src/gba/renderers/software-bg.c index 620f11e24..8c48b41ad 100644 --- a/src/gba/renderers/software-bg.c +++ b/src/gba/renderers/software-bg.c @@ -108,7 +108,7 @@ void GBAVideoSoftwareRendererDrawBackgroundMode3(struct GBAVideoSoftwareRenderer BACKGROUND_BITMAP_INIT; uint32_t color = renderer->normalPalette[0]; - if (mosaicWait && localX >= 0 && localY >= 0) { + if (mosaicWait && localX >= 0 && localY >= 0 && (localX >> 8) < GBA_VIDEO_HORIZONTAL_PIXELS && (localY >> 8) < GBA_VIDEO_VERTICAL_PIXELS) { LOAD_16(color, ((localX >> 8) + (localY >> 8) * GBA_VIDEO_HORIZONTAL_PIXELS) << 1, renderer->d.vram); color = mColorFrom555(color); } @@ -151,7 +151,7 @@ void GBAVideoSoftwareRendererDrawBackgroundMode4(struct GBAVideoSoftwareRenderer if (GBARegisterDISPCNTIsFrameSelect(renderer->dispcnt)) { offset = 0xA000; } - if (mosaicWait && localX >= 0 && localY >= 0) { + if (mosaicWait && localX >= 0 && localY >= 0 && (localX >> 8) < GBA_VIDEO_HORIZONTAL_PIXELS && (localY >> 8) < GBA_VIDEO_VERTICAL_PIXELS) { color = ((uint8_t*)renderer->d.vram)[offset + (localX >> 8) + (localY >> 8) * GBA_VIDEO_HORIZONTAL_PIXELS]; } @@ -192,7 +192,7 @@ void GBAVideoSoftwareRendererDrawBackgroundMode5(struct GBAVideoSoftwareRenderer if (GBARegisterDISPCNTIsFrameSelect(renderer->dispcnt)) { offset = 0xA000; } - if (mosaicWait && localX >= 0 && localY >= 0) { + if (mosaicWait && localX >= 0 && localY >= 0 && (localX >> 8) < 160 && (localY >> 8) < 128) { LOAD_16(color, offset + (localX >> 8) * 2 + (localY >> 8) * 320, renderer->d.vram); color = mColorFrom555(color); }