Engine:
* Ensure support libs are unloaded properly before trying to call Mix_CloseAudio() - fixes SegFault when running newer versions of SDL_mixer
--- a/hedgewars/uSound.pas Tue Mar 30 17:17:15 2010 +0000
+++ b/hedgewars/uSound.pas Tue Mar 30 17:44:02 2010 +0000
@@ -83,6 +83,12 @@
if isSoundEnabled then
isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
+{$IFDEF SDL_MIXER_NEWER}
+ WriteToConsole('Init SDL_mixer... ');
+ SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
+ WriteLnToConsole(msgOK);
+{$ENDIF}
+
if isSoundEnabled then
WriteLnToConsole(msgOK)
else
@@ -108,7 +114,15 @@
if voicepacks[t].chunks[i] <> nil then
Mix_FreeChunk(voicepacks[t].chunks[i]);
-Mix_FreeMusic(Mus);
+if Mus <> nil then
+ Mix_FreeMusic(Mus);
+
+{$IFDEF SDL_MIXER_NEWER}
+// make sure all instances of sdl_mixer are unloaded before continuing
+while Mix_Init(0) <> 0 do
+ Mix_Quit();
+{$ENDIF}
+
Mix_CloseAudio();
end;
@@ -119,12 +133,6 @@
begin
if not isSoundEnabled then exit;
-{$IFDEF SDL_MIXER_NEWER}
- WriteToConsole('Init SDL_mixer... ');
- SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
- WriteLnToConsole(msgOK);
-{$ENDIF}
-
defVoicepack:= AskForVoicepack('Default');
for i:= Low(TSound) to High(TSound) do
@@ -150,9 +158,6 @@
else
WriteLnToConsole(msgOK)
end;
-{$IFDEF SDL_MIXER_NEWER}
- Mix_Quit();
-{$ENDIF}
end;
procedure PlaySound(snd: TSound);