[a5] crash on al_get_joystick
Mark Oates

Something with allegro 5.1.11 is causing allegro to crash when calling al_get_joystick(n) where a joystick is not available. It used to simply return NULL if a joystick did not exist, but now in 5.1.11 appears to cause a crash. If the stick is there, everything is fine.

A simple example:

#include <allegro5/allegro.h>

int main(int argc, char *argv[])
  ALLEGRO_JOYSTICK *joy = al_get_joystick(0);
                        // ^ if no joystick is there, program will crash.
  return 0;

I'm using Edgar's 5.1.11 binary build (used in speedhack).


It's possible that a bug was introduced there. Probably by me :-[
Are you able to debug and pinpoint the exact point of failure?

Peter Hull

Tried this on the allegro-msvc2013-x86-5.1.11 I got from sourceforge, compiling your program under VS 2013. No crashes, it just returned NULL as you'd expect.
On OSX you get an assert fail and an abort, which is inconsistent and maybe needs to be fixed?*


*Docs say


Get a handle for a joystick on the system. The number may be from 0 to
al_get_num_joysticks-1. If successful a pointer to a joystick
object is returned, which represents a physical device. Otherwise NULL
is returned.

I dunno, what does Allegro usually do with an out of range value?


Assertion is the usual way, and the documentation clearly states that you cannot pass an out of range value. However I feel we're gradually changing the assertion error handling to returning NULL, so it probably would be fine to change and document it in this case.

Bruce Pascoe

My guess is it's regression introduced by the recent stabilization of the Windows joystick code. It used to crash on init if XInput wasn't available (e.g. WinXP)

Thread #615549. Printed from Allegro.cc