<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Mouse problems in Allegro 4.9.8</title>
		<link>http://www.allegro.cc/forums/view/599242</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 28 Feb 2009 06:35:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m writing some simple programs to learn the new API and I have this problem: <i>al_get_mouse_state()</i> keeps crashing on my machine. I&#39;ve been trying to spot the problem and compared the code practically line to line with the one in <i>ex_mouse_focus.c</i> and found that the only difference was the creation of one more <i>ALLEGRO_DISPLAY</i>. If I create two <i>ALLEGRO_DISPLAY</i>s, the program no longer crashes on <i>al_get_mouse_state()</i>.</p><p>If I create only one <i>ALLEGRO_DISPLAY</i> and use <i>al_get_mouse_state()</i>, the program crashes. Anyone else has this problem? or is there something wrong with my Allegro 4.9.8 setup?.</p><p>Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Mon, 16 Feb 2009 01:13:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What platform are you using?<br />Also, even if it&#39;s a very simple change, please attach your example program (it&#39;s easier to compile and run yours than to modify an existing example ourselves).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 16 Feb 2009 01:18:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m using MinGW on Windows XP.</p><p>I reduced the program down to this:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;stdio.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;allegro5/allegro5.h&gt;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">static</span> ALLEGRO_DISPLAY <span class="k3">*</span>display<span class="k2">;</span></td></tr><tr><td class="number">7</td><td><span class="c">//static ALLEGRO_DISPLAY *display2 = NULL;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">12</td><td>  ALLEGRO_LOCKED_REGION lr<span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  ALLEGRO_KEYBOARD_STATE key_state<span class="k2">;</span></td></tr><tr><td class="number">14</td><td>  ALLEGRO_MOUSE_STATE mouse_state<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_init<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">17</td><td>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Could not init Allegro.\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">20</td><td>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_install_mouse<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">21</td><td>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Could not init mouse.\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_install_keyboard<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">25</td><td>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Could not init keyboard.\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">28</td><td>  display <span class="k3">=</span> al_create_display<span class="k2">(</span><span class="n">300</span>, <span class="n">300</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">29</td><td><span class="c">//  display2 = al_create_display(300, 300);</span></td></tr><tr><td class="number">30</td><td>  al_set_window_title<span class="k2">(</span><span class="s">"Allegro 4.9.8 Test"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">31</td><td>&#160;</td></tr><tr><td class="number">32</td><td>  al_get_keyboard_state<span class="k2">(</span><span class="k3">&amp;</span>key_state<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">33</td><td>  <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>al_key_down<span class="k2">(</span><span class="k3">&amp;</span>key_state, ALLEGRO_KEY_ESCAPE<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">34</td><td>    al_get_mouse_state<span class="k2">(</span><span class="k3">&amp;</span>mouse_state<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">35</td><td>&#160;</td></tr><tr><td class="number">36</td><td>    al_rest<span class="k2">(</span><span class="n">0</span>.<span class="n">15</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">37</td><td>    al_get_keyboard_state<span class="k2">(</span><span class="k3">&amp;</span>key_state<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">38</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">39</td><td>&#160;</td></tr><tr><td class="number">40</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">41</td><td><span class="k2">}</span></td></tr><tr><td class="number">42</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>
This code crashes, but if I uncomment the lines for <i>display2</i>, the program runs fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Mon, 16 Feb 2009 02:03:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The program doesn&#39;t crash here for me (MinGW/Vista). Could you provide a backtrace or any other useful info you can get?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Mon, 16 Feb 2009 02:40:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry, I&#39;ll find out how to do a backtrace and post back.</p><p>I&#39;ve tried compiling the program with the complete binary package in <i>allegro5.org</i> installed and it keeps crashing, so I think it might be a problem with my drivers or something.</p><p>[EDIT:] I don&#39;t know how to do a proper bakctrace. I&#39;ve tried some simple instructions I found, but this is all I get:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
GNU gdb 6.8<br />Copyright (C) 2008 Free Software Foundation, Inc.<br />License GPLv3+: GNU GPL version 3 or later &lt;<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>&gt;<br />This is free software: you are free to change and redistribute it.<br />There is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;<br />and &quot;show warranty&quot; for details.<br />This GDB was configured as &quot;i686-pc-mingw32&quot;...<br />(no debugging symbols found)<br />(gdb) run<br />Starting program: C:\allegro.cc\Allegro5/Allegro5Test.exe<br />[New thread 1384.0xef8]<br />(no debugging symbols found)<br />(no debugging symbols found)<br />[New thread 1384.0x86c]<br />[New thread 1384.0x80]</p><p>Program received signal SIGSEGV, Segmentation fault.<br />0x6347589c in mouse_directx_get_state (ret_state=0x22fe20)<br />    at C:\Users\trent\4.9.8\src\win\wmouse.c:1048<br />1048    C:\Users\trent\4.9.8\src\win\wmouse.c: No such file or directory.<br />        in C:\Users\trent\4.9.8\src\win\wmouse.c<br />(gdb) backtrace<br />#0  0x6347589c in mouse_directx_get_state (ret_state=0x22fe20)<br />    at C:\Users\trent\4.9.8\src\win\wmouse.c:1048<br />#1  0x6347589c in mouse_directx_get_state (ret_state=0x1)<br />    at C:\Users\trent\4.9.8\src\win\wmouse.c:1048<br />Backtrace stopped: frame did not save the PC<br />(gdb) quit
</p></div></div><p>

On the other hand, the program doesn&#39;t crash if compiled with the 4.9.7 binary package.</p><p>[EDIT 2:] I built the debug lib on my machine &#39;cause it doesn&#39;t come with the binary package. Here&#39;s what I get now:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
GNU gdb 6.8<br />Copyright (C) 2008 Free Software Foundation, Inc.<br />License GPLv3+: GNU GPL version 3 or later &lt;<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>&gt;<br />This is free software: you are free to change and redistribute it.<br />There is NO WARRANTY, to the extent permitted by law.  Type &quot;show copying&quot;<br />and &quot;show warranty&quot; for details.<br />This GDB was configured as &quot;i686-pc-mingw32&quot;...<br />(no debugging symbols found)<br />(gdb) run<br />Starting program: C:\allegro.cc\Allegro5/Allegro5Test.exe<br />[New thread 496.0x1d0]<br />(no debugging symbols found)<br />(no debugging symbols found)<br />[New thread 496.0x1e4]<br />[New thread 496.0x1e0]</p><p>Program received signal SIGSEGV, Segmentation fault.<br />0x625b4025 in mouse_directx_get_state (ret_state=0x22fe10)<br />    at C:/allegro-4.9.8/src/win/wmouse.c:1048<br />1048          the_mouse.state.display = win_disp-&gt;is_mouse_on ? (void*)win_disp : NULL;<br />(gdb) backtrace<br />#0  0x625b4025 in mouse_directx_get_state (ret_state=0x22fe10)<br />    at C:/allegro-4.9.8/src/win/wmouse.c:1048<br />#1  0x6259d5fe in al_get_mouse_state (ret_state=0x22fe10)<br />    at C:/allegro-4.9.8/src/mousenu.c:250<br />#2  0x00401440 in _mangled_main ()<br />#3  0x625b4348 in _WinMain (_main=0x4012e0, hInst=0x400000, hPrev=0x0,<br />    Cmd=0x241f1b &quot;&quot;, nShow=10) at C:/allegro-4.9.8/src/win/wnewsys.c:136<br />#4  0x0040152d in WinMain@16 ()<br />#5  0x00401851 in main ()<br />(gdb) quit
</p></div></div><p>

And this is the content of the <i>allegro.log</i> file:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
ALLEGRO_SYSTEM_INTERFACE created.<br />al-winput INFO: Input thread started.<br />Render-to-texture: 1<br />al-wmouse INFO: mouse handler starts<br />faux_fullscreen=0<br />Normal window<br />BeginScene succeeded in create_device<br />Success<br />al-wmouse WARNING: mouse device not acquired or lost
</p></div></div><p>

I understand that the fault may be on my side, so I&#39;m posting this just in case it&#39;s useful for the Allegro 5 devs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Mon, 16 Feb 2009 10:25:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am having the same issues with it (the mouse state) too using Visual Studio 2008 Pro on Vista. My other post is <a href="http://www.allegro.cc/forums/thread/599171/796905#target">here</a>. I have not tried to create another display to see if that helps, but I guess it can&#39;t hurt. The funny thing is, is that it doesn&#39;t crash every time...seems to be random. I can only guess something screwy in the mouse code.:-/ I&#39;ll try and take a look in the source to see if I can figure out what the hell is going on.:&#39;(</p><p><s>
Edit:
It seems that the mouse driver gets confused as to what the current display is. If you add a call to: al_set_current_display, then at least so far...it doesn&#39;t crash. I am assuming this should solve your problem as well.:D I don&#39;t know exactly where or how to fix this in the allegro source, but I&#39;m sure someone (Peter,Elias,Evert,etc) could find it...:D
</s><br />Spoke too soon, I&#39;m afraid. Maybe just creating another display and delete it after setting the current display would work.???</p><p>Edit2:<br />Yeah...that seems to work (at least after about 20 runs it hasn&#39;t crashed.::)). That is really weird. I am just lost in the source...I&#39;ll keep digging though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Don Freeman)</author>
		<pubDate>Sat, 28 Feb 2009 02:06:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve fixed this in SVN after 4.9.8 come out.<br /><a href="http://alleg.svn.sourceforge.net/viewvc/alleg/allegro/branches/4.9/src/win/wmouse.c?r1=11634&amp;r2=11633&amp;pathrev=11634">http://alleg.svn.sourceforge.net/viewvc/alleg/allegro/branches/4.9/src/win/wmouse.c?r1=11634&amp;r2=11633&amp;pathrev=11634</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Sat, 28 Feb 2009 03:37:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry, didn&#39;t notice that. It works perfectly now.:D
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Don Freeman)</author>
		<pubDate>Sat, 28 Feb 2009 06:35:38 +0000</pubDate>
	</item>
</rss>
