forked from Mirrors/openclonk
Make GTK+ and SDL2 work together
If the gamepad code initialized the SDL video subsystem, GTK+ crashed in libX11. Or something along those lines. Making the optional subsystems using SDL for gamepads and audio use SDL_InitSubSystem and only the SDL Application port do the full SDL_Init is the proper way to do things in any case.liquid_container
parent
623f838799
commit
4b4b8781a0
|
@ -302,9 +302,12 @@ endif()
|
|||
# SDL
|
||||
if(USE_SDL_MAINLOOP)
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
elseif(NOT WIN32)
|
||||
# for gamepads
|
||||
find_package(SDL2)
|
||||
endif()
|
||||
set(HAVE_SDL ${SDL2_FOUND})
|
||||
include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})
|
||||
|
||||
############################################################################
|
||||
# generated source files
|
||||
|
|
|
@ -116,9 +116,9 @@ bool C4AbstractApp::Init(int argc, char * argv[])
|
|||
// Set locale
|
||||
setlocale(LC_ALL,"");
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
Log("Error initializing SDL.");
|
||||
LogF("SDL_Init: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,16 +184,16 @@ bool C4GamePadControl::AnyButtonDown()
|
|||
|
||||
C4GamePadControl::C4GamePadControl()
|
||||
{
|
||||
// Initialize SDL, if necessary.
|
||||
if (!SDL_WasInit(SDL_INIT_JOYSTICK)
|
||||
&& SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE))
|
||||
LogF("SDL: %s", SDL_GetError());
|
||||
// FIXME: Port to SDL_INIT_GAMECONTROLLER
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) != 0)
|
||||
LogF("SDL_InitSubSystem(SDL_INIT_JOYSTICK): %s", SDL_GetError());
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
if (!SDL_NumJoysticks()) Log("No Gamepad found");
|
||||
}
|
||||
|
||||
C4GamePadControl::~C4GamePadControl()
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_EVENTS);
|
||||
}
|
||||
|
||||
void C4GamePadControl::Execute(bool)
|
||||
|
|
|
@ -69,9 +69,9 @@ bool C4MusicSystem::InitializeMOD()
|
|||
LogF("SDL_mixer runtime version is %d.%d.%d (compiled with %d.%d.%d)",
|
||||
link_version->major, link_version->minor, link_version->patch,
|
||||
compile_version.major, compile_version.minor, compile_version.patch);
|
||||
if (!SDL_WasInit(SDL_INIT_AUDIO) && SDL_Init(SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE))
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0)
|
||||
{
|
||||
LogF("SDL: %s", SDL_GetError());
|
||||
LogF("SDL_InitSubSystem(SDL_INIT_AUDIO): %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
//frequency, format, stereo, chunksize
|
||||
|
@ -112,7 +112,7 @@ void C4MusicSystem::DeinitializeMOD()
|
|||
{
|
||||
#if AUDIO_TK == AUDIO_TK_SDL_MIXER
|
||||
Mix_CloseAudio();
|
||||
SDL_Quit();
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
#elif AUDIO_TK == AUDIO_TK_OPENAL
|
||||
#ifndef __APPLE__
|
||||
alutExit();
|
||||
|
|
Loading…
Reference in New Issue