<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro SVN &amp; Retrieving Display Modes</title>
		<link>http://www.allegro.cc/forums/view/599604</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 18 Mar 2009 01:22:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I &quot;upgraded&quot; to the latest SVN version today (from being between 4.9.7 release and 4.9.8 release, again, with SVN) and I ran into a strange problem.</p><p>I compiled Allegro as a shared library. No problems during compiling, everything went fine. I then had to make a few modifications to my game-thing, as expected. After it finally compiled properly, I tried to run it...and it crashed. I ran it through a debugger, and it crashed when it called the function <tt>al_get_num_display_modes</tt> in a loop, the first time it was called.</p><p>The example program is as follows:</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;allegro5/allegro5.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;stdio.h&gt;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span></td></tr><tr><td class="number">5</td><td><span class="k2">{</span></td></tr><tr><td class="number">6</td><td>  <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></td></tr><tr><td class="number">7</td><td>  </td></tr><tr><td class="number">8</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></td></tr><tr><td class="number">9</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">10</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">"Allegro failed to be initialized."</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">13</td><td>  </td></tr><tr><td class="number">14</td><td>  <span class="k1">for</span> <span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> <span class="k3">&lt;</span> al_get_num_display_modes<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a><span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">15</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>    ALLEGRO_DISPLAY_MODE mode<span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    </td></tr><tr><td class="number">18</td><td>    al_get_display_mode<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a>, <span class="k3">&amp;</span>mode<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>    </td></tr><tr><td class="number">20</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">"Mode %d:\n"</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a><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">"\t%d x %d @ %d"</span>, mode.width, mode.height,</td></tr><tr><td class="number">22</td><td>      mode.refresh_rate<span class="k2">)</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>  </td></tr><tr><td class="number">25</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td><span class="k2">}</span></td></tr><tr><td class="number">27</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>

Allegro initializes, but it crashes on <tt>al_get_num_display_modes()</tt>. The backtrace is as so:</p><p><tt>(gdb) bt
#0  _al_deduce_color_format (eds=0x0)
    at C:/Users/veiva/Desktop/Allegro/4.9.8/src/display_settings.c:535
#1  0x6b6b2795 in win_get_num_display_modes ()
    at C:/Users/veiva/Desktop/Allegro/4.9.8/src/win/wnewsys.c:271
#2  0x00401327 in _mangled_main ()
#3  0x6b6b249b in _WinMain (_main=0x4012f0, hInst=0x400000, hPrev=0x0,
    Cmd=0x4e22e0 &quot;&quot;, nShow=10)
    at C:/Users/veiva/Desktop/Allegro/4.9.8/src/win/wnewsys.c:136
#4  0x004013b3 in WinMain@16 ()
#5  0x004014e0 in main ()</tt></p><p>It crashes because <tt>_al_get_new_display_settings()</tt> returns zero, as this part of GDB shows:</p><p><tt>Breakpoint 1, win_get_num_display_modes ()
    at C:/Users/veiva/Desktop/Allegro/4.9.8/src/win/wnewsys.c:271
271        int format = _al_deduce_color_format(_al_get_new_display_settings());

(gdb) s
_al_get_new_display_settings ()
    at C:/Users/veiva/Desktop/Allegro/4.9.8/src/tls.c:247
247        if ((tls = tls_get()) == NULL)
(gdb) n
248           return 0;
(gdb)</tt> </p><p>Yet, if I go &quot;<tt>p tls</tt>,&quot; it shows a valid pointer. If I go &quot;<tt>p *tls</tt>,&quot; it shows this:</p><p><tt>(gdb) p *tls
$1 = {new_display_refresh_rate = 0, new_display_flags = 0,
  new_display_settings = 0x0, current_display = &lt;incomplete type&gt;,
  target_bitmap = &lt;incomplete type&gt;, new_bitmap_format = 0,
  new_bitmap_flags = 0, blend_source = 2, blend_dest = 3,
  blend_alpha_source = 2, blend_alpha_dest = 3, blend_color = {r = 1, g = 1,
    b = 1, a = 1}, allegro_errno = 2}</tt></p><p>I compiled Allegro with these commands (or at least, I hope I did! But it&#39;s surely a shared library...):</p><p><tt>mkdir build
cd build
cmake .. -G &quot;MinGW Makefiles&quot;
make
make install</tt></p><p>I just want to get my game-thing up and running again! <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> Please tell me which stupid mistake I did!</p><p>[edit]Oh, my GCC version is 3.4.5, if that&#39;s of any help!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Tue, 17 Mar 2009 00:30:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, can confirm this here. We need to fix it before 4.9.9.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 17 Mar 2009 20:11:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Elias said:</div><div class="quote"><p>Thanks, can confirm this here. We need to fix it before 4.9.9. </p></div></div><p>

Thank you! I was rereading the manual and all, thinking I missed something important that changed since somewhere between 4.9.7 and 4.9.8!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Tue, 17 Mar 2009 20:43:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you try calling al_reset_display_options() after al_init()? That should work around it but I&#39;m too lazy to try. Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Wed, 18 Mar 2009 01:00:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Doing so stops it from crashing, but then <tt>al_get_num_display_modes</tt> returns -1, as shown by GDB:</p><pre>(gdb) p al_get_num_display_modes()
$1 = -1</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Wed, 18 Mar 2009 01:11:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You also have to call al_set_new_display_flags(ALLEGRO_FULLSCREEN) apparently.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Wed, 18 Mar 2009 01:22:29 +0000</pubDate>
	</item>
</rss>
