From ded654381712f4f47ff4e880e1336cae69d13ffe Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 28 Jun 2021 13:32:27 +0700 Subject: [PATCH] don't exit if joystick initialization failed, better report SDL_Init errors (#229) --- Source/i_main.c | 4 ++-- Source/i_sound.c | 5 +++-- Source/i_system.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/i_main.c b/Source/i_main.c index 6f0d7491..cc543aca 100644 --- a/Source/i_main.c +++ b/Source/i_main.c @@ -35,7 +35,7 @@ #include "i_system.h" // haleyjd: SDL init flags -#define BASE_INIT_FLAGS (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) +#define BASE_INIT_FLAGS SDL_INIT_VIDEO #ifdef _DEBUG #define INIT_FLAGS (BASE_INIT_FLAGS | SDL_INIT_NOPARACHUTE) @@ -51,7 +51,7 @@ int main(int argc, char **argv) // haleyjd: init SDL if(SDL_Init(INIT_FLAGS) == -1) { - puts("Failed to initialize SDL library.\n"); + printf("Failed to initialize SDL library: %s\n", SDL_GetError()); return -1; } diff --git a/Source/i_sound.c b/Source/i_sound.c index 156e26da..4c8501ce 100644 --- a/Source/i_sound.c +++ b/Source/i_sound.c @@ -669,9 +669,10 @@ void I_InitSound(void) audio_buffers = SAMPLECOUNT * snd_samplerate / 11025; // haleyjd: the docs say we should do this - if(SDL_InitSubSystem(SDL_INIT_AUDIO)) + // In SDL2, SDL_InitSubSystem() and SDL_Init() are interchangeable. + if (SDL_Init(SDL_INIT_AUDIO) < 0) { - printf("Couldn't initialize SDL audio.\n"); + printf("Couldn't initialize SDL audio: %s\n", SDL_GetError()); snd_card = 0; mus_card = 0; return; diff --git a/Source/i_system.c b/Source/i_system.c index cadef762..5cceaee9 100644 --- a/Source/i_system.c +++ b/Source/i_system.c @@ -170,6 +170,7 @@ void I_InitJoystick(void) if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { + printf("Failed to initialize joystick: %s\n", SDL_GetError()); return; }