From 67956c9f2c4bf666ca4555998cc19b700a7e5ff5 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 30 Aug 2007 08:10:32 +0000 Subject: [PATCH] [win] bug #1658288 - crashes when sound is disabled --- src/drivers/win/sound.cpp | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/drivers/win/sound.cpp b/src/drivers/win/sound.cpp index 2e6a3292..59cc45ee 100644 --- a/src/drivers/win/sound.cpp +++ b/src/drivers/win/sound.cpp @@ -249,12 +249,40 @@ public: } }; +//todo - a properly synchronized method ShouldntTouchSound() which is totally safe (use mutexes) and use that to guard all sound code +//also add an alternate timer-based throttler for when sound is disabled + static Player *player; static Player8 *player8; +static bool trashPending = false; + +void TrashSound() { + trashPending = true; +} + +void DoTrashSound() { + if(dsout) delete dsout; + if(player) delete player; + dsout = 0; + player = 0; + trashPending = false; +} + +bool CheckTrashSound() { + if(trashPending) + { + DoTrashSound(); + return true; + } + else return false; +} + void win_Throttle() { - player->throttle(); + if(CheckTrashSound()) return; + if(player) + player->throttle(); } void win_SoundInit(int bits) { @@ -277,14 +305,6 @@ void win_SoundInit(int bits) { dsout->unlock(); } -void TrashSound() { - if(dsout) delete dsout; - if(player) delete player; - dsout = 0; - player = 0; -} - - int InitSound() { if(soundoptions&SO_FORCE8BIT) @@ -308,14 +328,15 @@ int InitSound() { void win_SoundSetScale(int scale) { - player->scale = scale; + if(CheckTrashSound()) return; + if(player) + player->scale = scale; } void win_SoundWriteData(int32 *buffer, int count) { - - //todo.. - // FCEUI_AviSoundUpdate((void*)MBuffer, Count); - + //mbg 8/30/07 - this used to be done here, but now its gtting called from somewhere else... + //FCEUI_AviSoundUpdate((void*)MBuffer, Count); + if(CheckTrashSound()) return; void *tempbuf = alloca(2*count); short *sbuf = (short *)tempbuf; for(int i=0;i