From dbbc49dc17dab9d422675aa63096b595d95aabeb Mon Sep 17 00:00:00 2001 From: TC1995 Date: Thu, 10 Jul 2025 01:47:19 +0200 Subject: [PATCH] Add sanity checks to the Gameport pointer (July 10th, 2025) Fixes hangs/crashes when disabled on win3.1x and other software. --- src/sound/snd_sb.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index e612250b7..cb2ede45a 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -1152,11 +1152,13 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *priv) else if ((val & 0x06) == 0x02) mpu401_change_addr(sb->mpu, 0); } - sb->gameport_addr = 0; - gameport_remap(sb->gameport, 0); - if (!(val & 0x01)) { - sb->gameport_addr = 0x200; - gameport_remap(sb->gameport, 0x200); + if (sb->gameport != NULL) { + sb->gameport_addr = 0; + gameport_remap(sb->gameport, 0); + if (!(val & 0x01)) { + sb->gameport_addr = 0x200; + gameport_remap(sb->gameport, 0x200); + } } } break; @@ -1371,7 +1373,7 @@ sb_ct1745_mixer_read(uint16_t addr, void *priv) else ret = 0x06; /* Should never happen. */ } - if (!sb->gameport_addr) + if (!sb->gameport_addr && (sb->gameport != NULL)) ret |= 0x01; break; @@ -1619,7 +1621,8 @@ ess_mixer_write(uint16_t addr, uint8_t val, void *priv) ess_fm_midi_write, NULL, NULL, ess); - gameport_remap(ess->gameport, !(mixer->regs[0x40] & 0x2) ? 0x00 : 0x200); + if (ess->gameport != NULL) + gameport_remap(ess->gameport, !(mixer->regs[0x40] & 0x2) ? 0x00 : 0x200); if (ess->dsp.sb_subtype > SB_SUBTYPE_ESS_ES1688) { /* Not on ES1688. */