[Freeciv-Dev] Re: (PR#2700) SDL_init can only be called once
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Dnia 2003.01.02 02:32 Jason Short via RT napisa³(a):
>
> SDL_init() cannot generally be called more than once. Even if you
> uninitialize SDL, you can't call it again. And this means SDL sound
> doesn't work with the SDL client, since both call SDL_init.
>
> The fix should introduce a common client method of initializing SDL.
> Something like init_sdl(options) which will only initialize once. And
> SDL should not be uninitted until the client exits (for instance when
> we
> uninitialize a sound module it should not be done, since we may switch
> back to that sound module later).
>
> autoconf changes may also be needed to see if any SDL users are being
> compiled. The check could be something like
> #if defined SDL_AUDIO or defined SDL_CLIENT
> or
> #ifdef USING_SDL
>
> A patch for this would be welcome.
>
Patch ordered ... Patch send :)
Rafal
----------------------------------------------------------------------
WIADOMOSCI, fakty, wydarzenia... >>> http://link.interia.pl/f16b2
diff -u -r freeciv/client/audio_sdl.c fc4/client/audio_sdl.c
--- freeciv/client/audio_sdl.c Mon Sep 2 04:19:53 2002
+++ fc4/client/audio_sdl.c Thu Jan 2 16:35:52 2003
@@ -126,6 +126,30 @@
}
}
+static void quit_sdl_audio(void)
+{
+ if ( SDL_WasInit( SDL_INIT_VIDEO ) )
+ {
+ SDL_QuitSubSystem( SDL_INIT_AUDIO );
+ }
+ else
+ {
+ SDL_Quit();
+ }
+}
+
+static int init_sdl_audio(void)
+{
+ if ( SDL_WasInit( SDL_INIT_VIDEO ) )
+ {
+ return SDL_InitSubSystem( SDL_INIT_AUDIO );
+ }
+ else
+ {
+ return SDL_Init( SDL_INIT_AUDIO );
+ }
+}
+
/**************************************************************************
Clean up.
**************************************************************************/
@@ -145,7 +169,7 @@
Mix_FreeMusic(mus);
Mix_CloseAudio();
- SDL_Quit();
+ quit_sdl_audio();
}
/**************************************************************************
@@ -159,14 +183,14 @@
const int audio_channels = 2;
int i;
- if (SDL_Init(SDL_INIT_AUDIO) < 0) {
+ if ( init_sdl_audio() < 0) {
return FALSE;
}
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
freelog(LOG_ERROR, "Error calling Mix_OpenAudio");
/* try something else */
- SDL_Quit();
+ quit_sdl_audio();
return FALSE;
}
diff -u -r freeciv/client/gui-sdl/graphics.c fc4/client/gui-sdl/graphics.c
--- freeciv/client/gui-sdl/graphics.c Thu Jan 2 13:47:02 2003
+++ fc4/client/gui-sdl/graphics.c Thu Jan 2 16:21:27 2003
@@ -702,12 +702,27 @@
Main.screen = NULL;
Main.rects_count = 0;
-
- if (SDL_Init(iFlags) < 0) {
- freelog(LOG_FATAL, _("(File %s line %d):"
+
+
+
+ if ( SDL_WasInit( SDL_INIT_AUDIO ))
+ {
+ if (SDL_InitSubSystem(iFlags) < 0) {
+ freelog(LOG_FATAL, _("(File %s line %d):"
+ "Unable to initialize SDL library : %s"),
+ __FILE__, __LINE__, SDL_GetError());
+ exit(1);
+ }
+ }
+ else
+ {
+ if (SDL_Init(iFlags) < 0) {
+ freelog(LOG_FATAL, _("(File %s line %d):"
"Unable to initialize SDL library : %s"),
__FILE__, __LINE__, SDL_GetError());
- exit(1);
+ exit(1);
+ }
+
}
atexit(SDL_Quit);
|
|