diff --git a/CHANGES b/CHANGES index 18aeb6b50..96ce5bf93 100644 --- a/CHANGES +++ b/CHANGES @@ -67,6 +67,7 @@ Misc: - Qt: Add application icon and XDG desktop files - GBA Thread: Split GBASync into a separate file - SDL: Properly check for initialization + - SDL: Clean up initialization functions 0.2.1: (2015-05-13) Bugfixes: diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index 7b4017d41..fea425f41 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -18,7 +18,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len); bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContext) { if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { - GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system"); + GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system: %s", SDL_GetError()); return false; } diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 9046b4463..e316a7f2f 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -33,19 +33,23 @@ static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble); static void _GBASDLRotationSample(struct GBARotationSource* source); bool GBASDLInitEvents(struct GBASDLEvents* context) { - int subsystem = SDL_INIT_JOYSTICK; -#if SDL_VERSION_ATLEAST(2, 0, 0) - subsystem |= SDL_INIT_HAPTIC | SDL_INIT_VIDEO; - - SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); -#endif #if SDL_VERSION_ATLEAST(2, 0, 4) SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); #endif - if (SDL_InitSubSystem(subsystem) < 0) { - return false; + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { + GBALog(0, GBA_LOG_ERROR, "SDL joystick initialization failed: %s", SDL_GetError()); } +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) { + GBALog(0, GBA_LOG_ERROR, "SDL haptic initialization failed: %s", SDL_GetError()); + } + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + GBALog(0, GBA_LOG_ERROR, "SDL video initialization failed: %s", SDL_GetError()); + } +#endif + SDL_JoystickEventState(SDL_ENABLE); int nJoysticks = SDL_NumJoysticks(); if (nJoysticks > 0) { @@ -158,6 +162,10 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player player->joystick = 0; player->joystickIndex = SIZE_MAX; + if (events->playersAttached >= MAX_PLAYERS) { + return false; + } + #if SDL_VERSION_ATLEAST(2, 0, 0) player->rumble.d.setRumble = _GBASDLSetRumble; CircleBufferInit(&player->rumble.history, RUMBLE_PWM); @@ -178,10 +186,6 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player CircleBufferInit(&player->rotation.zHistory, sizeof(float) * GYRO_STEPS); player->rotation.p = player; - if (events->playersAttached >= MAX_PLAYERS) { - return false; - } - player->playerId = events->playersAttached; size_t firstUnclaimed = SIZE_MAX;