SDL: Fix crash when attempting to sample sensors with no controller attached

This commit is contained in:
Jeffrey Pfau 2016-01-31 23:52:03 -08:00
parent 78ef8523ac
commit c69c34ab2d
1 changed files with 6 additions and 0 deletions

View File

@ -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);