<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_install_joystick() segfaults on some Windows systems</title>
		<link>http://www.allegro.cc/forums/view/615417</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 01 Jun 2015 20:14:17 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So far I&#39;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&#39;t been able to diagnose it myself because I can&#39;t reproduce it on any of my Win 8.1 machines...</p><p>For what it&#39;s worth, the particular crash is always a NULL dereference.  So something must not be being initialized properly and Allegro doesn&#39;t check for failure, leading to a crash.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Fri, 29 May 2015 07:33:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could you please detail where the crash happens? I probably programmed that, but I only tested it in a windows VM so it&#39;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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Fri, 29 May 2015 08:41:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#39;t work on XP to my knowledge...</p><p>All I know is that the crash happens during the course of the al_install_joystick() call.  I can&#39;t even work around it because the program crashes before returning from it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Fri, 29 May 2015 08:55:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Anything in the allegro.log? It&#39;ll at least tell you which joystick driver is being used.</p><p>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&#39;s the joystick section).</p><p>I&#39;ll have a look sometime soonish regardless, but the above things should help narrow down the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 29 May 2015 09:14:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Latest GIT build doesn&#39;t crash for me on Vista with MinGW 4.8.1 using al_install_joystick, and it is successful.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 29 May 2015 09:51:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, it only affects certain systems (and maybe only MSVC, I don&#39;t know).  It works fine for me on all my Win 8.1 machines, and in Wine apparently, but not in XP.</p><p>I will try to do some more troubleshooting to diagnose it.</p><p><b>Update:</b> Here&#39;s my allegro.log up to the crash:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a>   I             system.c:261  <a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a>                <span class="k2">[</span>   <span class="n">0</span>.<span class="n">01363</span><span class="k2">]</span> Allegro version: <span class="n">5</span>.<span class="n">1</span>.<span class="n">10</span> <span class="k2">(</span>WIP<span class="k2">)</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a>   D            wsystem.c:346  win_get_joystick_driver          <span class="k2">[</span>   <span class="n">0</span>.<span class="n">15541</span><span class="k2">]</span> Selected combined XInput<span class="k3">/</span>DirectInput joystick driver.
<a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a>   W            wsystem.c:729  _al_win_safe_load_library        <span class="k2">[</span>   <span class="n">0</span>.<span class="n">19493</span><span class="k2">]</span> PathFindOnPath failed to find xinput1_4.dll
<a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a>   W            wsystem.c:729  _al_win_safe_load_library        <span class="k2">[</span>   <span class="n">0</span>.<span class="n">19524</span><span class="k2">]</span> PathFindOnPath failed to find xinput1_3.dll
xinput   E             wjoyxi.c:249  load_xinput_module               <span class="k2">[</span>   <span class="n">0</span>.<span class="n">19529</span><span class="k2">]</span> Failed to load XInput library. Library is <span class="k1">not</span> installed.
</pre></div></div><p>

So it fails to load XInput and dies.</p><p><b>Edit:</b> Aaannd I found it.  wjoyxi.c, function joyxi_init_joystick():
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 527</span><span class="k1">static</span> <span class="k1">bool</span> joyxi_init_joystick<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="number"> 528</span><span class="k2">{</span>
<span class="number"> 529</span>   <span class="k1">int</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a><span class="k2">;</span>
<span class="number"> 530</span>
<span class="number"> 531</span>   load_xinput_module<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 532</span>
<span class="number"> 533</span>   <span class="c">/* Create the mutex and two condition variables. */</span>
<span class="number"> 534</span>   joyxi_mutex <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_mutex_recursive"><span class="a">al_create_mutex_recursive</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 535</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>joyxi_mutex<span class="k2">)</span>
<span class="number"> 536</span>      <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 537</span>   joyxi_cond <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_cond"><span class="a">al_create_cond</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 538</span>   <span class="c">// ...</span>
<span class="number"> 539</span><span class="k2">}</span>
</div></div><p>

It doesn&#39;t check the return value of load_xinput_module() and attempts to continue after initialization fails.</p><p><b>another edit:</b> 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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Fri, 29 May 2015 09:53:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, the joystick stuff should be fixed. No ideas yet about the DirectSound (which I assume is what&#39;s being triggered, unless you&#39;re still using OpenAL), as the code looks reasonably solid. Any logs for those crashes?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 30 May 2015 23:43:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Drat, how did I miss that? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> But fortunately it&#39;s a small mistake that was easily fixed. Thanks all for figuring this out and fixing this!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Sun, 31 May 2015 00:45:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nevermind, turns out the audio crash was on my end.  Seems I&#39;m not immune to this either: I called al_install_audio() and then tried to reserve samples without checking if it was successful.  Oops! <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><p>But thanks for getting that joystick bug fixed. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />  That one&#39;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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 31 May 2015 01:50:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If anybody wants an easy contribution idea to Allegro, add a whole bunch of <span class="source-code">__attribute__ <span class="k2">(</span><span class="k2">(</span>warn_unused_result<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span> (GCC/Clang), <span class="source-code">_Check_return_</span> (MSVC, that&#39;s right sal.h!) to Allegro&#39;s functions. This would be done by adding a new <span class="source-code">ALLEGRO_FUNC</span>-like (e.g. <span class="source-code">ALLEGRO_WARN_RESULT_FUNC</span>) macro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 31 May 2015 01:58:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s a good idea, maybe when I get some free time I&#39;ll see about doing that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 31 May 2015 02:18:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 01 Jun 2015 14:40:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are some that are useful for their side-effect (e.g. <span class="source-code"><a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a></span>). They are probably in the minority.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 01 Jun 2015 20:14:17 +0000</pubDate>
	</item>
</rss>
