Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_install_joystick() segfaults on some Windows systems

This thread is locked; no one can reply to it. rss feed Print
al_install_joystick() segfaults on some Windows systems
Bruce Pascoe
Member #15,931
April 2015
avatar

So far I've heard of this happening on a few systems. Originally I thought it was isolated to XP, but it seems newer Windows systems suffer from it as well: Calling al_install_joystick() causes a crash during the call. Unfortunately I haven't been able to diagnose it myself because I can't reproduce it on any of my Win 8.1 machines...

For what it's worth, the particular crash is always a NULL dereference. So something must not be being initialized properly and Allegro doesn't check for failure, leading to a crash.

beoran
Member #12,636
March 2011

Could you please detail where the crash happens? I probably programmed that, but I only tested it in a windows VM so it's possible that there is something different on your systems. If you can tell me where the crash happens I can investigate and try to write a workaround.

Bruce Pascoe
Member #15,931
April 2015
avatar

I can reproduce it in a Windows XP VM, however I have no way of getting it into a debugger. My app is compiled with VS 2013, which doesn't work on XP to my knowledge...

All I know is that the crash happens during the course of the al_install_joystick() call. I can't even work around it because the program crashes before returning from it.

SiegeLord
Member #7,827
October 2006
avatar

Anything in the allegro.log? It'll at least tell you which joystick driver is being used.

Additionally, you have some control over the joystick driver being used through the allegro5.cfg file (see the one that comes with the source for documentation, it's the joystick section).

I'll have a look sometime soonish regardless, but the above things should help narrow down the problem.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Bruce Pascoe
Member #15,931
April 2015
avatar

Yeah, it only affects certain systems (and maybe only MSVC, I don't know). It works fine for me on all my Win 8.1 machines, and in Wine apparently, but not in XP.

I will try to do some more troubleshooting to diagnose it.

Update: Here's my allegro.log up to the crash:

system   I             system.c:261  al_install_system                [   0.01363] Allegro version: 5.1.10 (WIP)
system   D            wsystem.c:346  win_get_joystick_driver          [   0.15541] Selected combined XInput/DirectInput joystick driver.
system   W            wsystem.c:729  _al_win_safe_load_library        [   0.19493] PathFindOnPath failed to find xinput1_4.dll
system   W            wsystem.c:729  _al_win_safe_load_library        [   0.19524] PathFindOnPath failed to find xinput1_3.dll
xinput   E             wjoyxi.c:249  load_xinput_module               [   0.19529] Failed to load XInput library. Library is not installed.

So it fails to load XInput and dies.

Edit: Aaannd I found it. wjoyxi.c, function joyxi_init_joystick():

#SelectExpand
527static bool joyxi_init_joystick(void) 528{ 529 int index; 530 531 load_xinput_module(); 532 533 /* Create the mutex and two condition variables. */ 534 joyxi_mutex = al_create_mutex_recursive(); 535 if (!joyxi_mutex) 536 return false; 537 joyxi_cond = al_create_cond(); 538 // ... 539}

It doesn't check the return value of load_xinput_module() and attempts to continue after initialization fails.

another edit: It also crashes initializing audio if there is no sound card installed. I found this out trying to run under Hyper-V, which has no audio support.

SiegeLord
Member #7,827
October 2006
avatar

Ok, the joystick stuff should be fixed. No ideas yet about the DirectSound (which I assume is what's being triggered, unless you're still using OpenAL), as the code looks reasonably solid. Any logs for those crashes?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

beoran
Member #12,636
March 2011

Drat, how did I miss that? :P But fortunately it's a small mistake that was easily fixed. Thanks all for figuring this out and fixing this!

Bruce Pascoe
Member #15,931
April 2015
avatar

Nevermind, turns out the audio crash was on my end. Seems I'm not immune to this either: I called al_install_audio() and then tried to reserve samples without checking if it was successful. Oops! :-X

But thanks for getting that joystick bug fixed. :) That one's been haunting me for ages, I never brought it up because it only seemed to affect WinXP, but I recently had a tester inform me of a crash on Win7 at the same spot, so it needed to get fixed.

SiegeLord
Member #7,827
October 2006
avatar

If anybody wants an easy contribution idea to Allegro, add a whole bunch of __attribute__ ((warn_unused_result)); (GCC/Clang), _Check_return_ (MSVC, that's right sal.h!) to Allegro's functions. This would be done by adding a new ALLEGRO_FUNC-like (e.g. ALLEGRO_WARN_RESULT_FUNC) macro.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Bruce Pascoe
Member #15,931
April 2015
avatar

That's a good idea, maybe when I get some free time I'll see about doing that.

beoran
Member #12,636
March 2011

Actually, is there any non-void Allegro function that we should NOT check? I thought that basically, any return value of Allegro must be checked in any serious non-example program.

SiegeLord
Member #7,827
October 2006
avatar

There are some that are useful for their side-effect (e.g. al_lock_bitmap). They are probably in the minority.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: