From c69c34ab2d419fa5ca605094e4afbb8f9e406a47 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 31 Jan 2016 23:52:03 -0800 Subject: [PATCH] SDL: Fix crash when attempting to sample sensors with no controller attached --- src/platform/sdl/sdl-events.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 8ca7a617b..323877e60 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -599,6 +599,9 @@ static void _GBASDLSetRumble(struct GBARumble* rumble, int enable) { #endif static int32_t _readTilt(struct GBASDLPlayer* player, int axis) { + if (!player->joystick) { + return 0; + } return SDL_JoystickGetAxis(player->joystick->joystick, axis) * 0x3800; } @@ -621,6 +624,9 @@ static int32_t _GBASDLReadGyroZ(struct GBARotationSource* source) { static void _GBASDLRotationSample(struct GBARotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; SDL_JoystickUpdate(); + if (!rotation->p->joystick) { + return; + } int x = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroX); int y = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroY);