Browse Source

Fix snd_deinit called even if snd_init failed

We were previously setting `was_sound_init` to true unconditionally
after calling `snd_init`.

However, `snd_init` can fail. Use `gbSndInited` instead.
pull/4412/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
b312edee49
  1. 4
      Source/diablo.cpp
  2. 2
      Source/effects.cpp

4
Source/diablo.cpp

@ -146,7 +146,6 @@ bool was_archives_init = false;
/** To know if surfaces have been initialized or not */
bool was_window_init = false;
bool was_ui_init = false;
bool was_snd_init = false;
void StartGame(interface_mode uMsg)
{
@ -1007,7 +1006,6 @@ void DiabloInit()
DiabloInitScreen();
snd_init();
was_snd_init = true;
ui_sound_init();
@ -1047,7 +1045,7 @@ void DiabloDeinit()
{
FreeItemGFX();
if (was_snd_init)
if (gbSndInited)
effects_cleanup_sfx();
snd_deinit();
if (was_ui_init)

2
Source/effects.cpp

@ -1283,6 +1283,8 @@ void PlaySfxLoc(_sfx_id psfx, Point position, bool randomizeByCategory)
void sound_stop()
{
if (!gbSndInited)
return;
ClearDuplicateSounds();
for (auto &sfx : sgSFX) {
if (sfx.pSnd != nullptr) {

Loading…
Cancel
Save