Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [a5] crash on al_get_joystick

This thread is locked; no one can reply to it. rss feed Print
[a5] crash on al_get_joystick
Mark Oates
Member #1,146
March 2001
avatar

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[])
{
  al_init();
  al_install_joystick();
  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).

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

beoran
Member #12,636
March 2011

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
Member #1,136
March 2001

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?*

Pete

*Docs say

Quote:

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?

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

Bruce Pascoe
Member #15,931
April 2015
avatar

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)

Go to: