Description: Avoid SDL's joystick API if it's uninitialised
Author: Alexandre Duret-Lutz <duret_g@epita.fr>
Bug-Debian: https://bugs.debian.org/169525
Last-Update: 2016-01-21

2002-04-07  Alexandre Duret-Lutz  <duret_g@epita.fr>

	* src/media/sdl/joystick.c (get_joystick_state): Make sure we
	  never use SDL's Joystick API if it wasn't initialized.
	  Reported by William Black.

--- heroes-0.21.orig/src/media/sdl/joystick.c
+++ heroes-0.21/src/media/sdl/joystick.c
@@ -63,6 +63,13 @@ char joyinit (void)
 
 void get_joystick_state (void)
 {
+  /* Make sure we never use SDL's Joystick API if it wasn't
+     initialized (this happens when the game is run with -J): crashes
+     have been reported by a Windows user.  More generally, avoid
+     these extra calls if no joystick was detected.  */
+  if (joystick_detected == 0)
+    return;
+
   SDL_JoystickUpdate();
   if (joystick[0]) {
     joystick_b[0] = (joystick_b[0] & ~1) |
