<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[bug] fbcon.c: second call to fb_init fails</title>
		<link>http://www.allegro.cc/forums/view/607523</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 05 Jun 2011 03:10:41 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi,</p><p>I&#39;m currently packaging liballegro 4.4.2 for the OpenWRT-based firmware of the <a href="http://en.qi-hardware.com/wiki/Ben_NanoNote">NanoNote mini-computer</a>, and stumbled into the following framebuffer driver bug:</p><p>The symptom is that all allegro programs that do set_gfx_mode twice, once with a gfx_autodetect and then a second time with gfx_save, fail to initialize the graphics device if the first set_gfx_mode() fails.  The first one fails pretty often on the NanoNote, since it only supports a single mode: 320x240x32bpp, and so most programs just fail.</p><p>The culprit is fb_init(), which closes the frame buffer device (&#39;close(fbfd)&#39;) when it fails to setup the requested video mode.  The device is then never re-opened, as there is an &quot;optimization&quot; at the start of fb_init() where it first checks that fb_mode_read is false:
</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"> 1</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k2">(</span><span class="k3">!</span>fb_mode_read<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k2">(</span>fb_open_device<span class="k2">(</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 2</span>      <span class="k1">return</span> NULL<span class="k2">;</span>
</div></div><p>
So after the first call to fb_init(), the fbfd file-descriptor is invalid and all subsequent attempts to set up a video-mode fail.  I patched it for now by adding fb_mode_read=FALSE before exiting.  </p><p>My patch is here:</p><p><a href="http://projects.qi-hardware.com/index.php/p/openwrt-packages/source/tree/trunk/liballegro/patches/020-fix-fbcon-init.patch">http://projects.qi-hardware.com/index.php/p/openwrt-packages/source/tree/trunk/liballegro/patches/020-fix-fbcon-init.patch</a></p><p>Most of it is joust &#39;noise&#39; adding tracers to see what&#39;s going on.  Also the patch doesn&#39;t catch all the places where fb_init() closes fbfd, only the one occurrence that was a problem for us.</p><p>Maybe somebody with more understanding of the driver could have a look at what&#39;s a proper fix.  Maybe the check for fb_mode_read should be replaced with a check for &#39;fbfd&gt;=0&#39; because &quot;mode read&quot; and &quot;fb descriptor valid&quot; seem to be two different things altogether.</p><p>cheers,</p><p>David
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dvdkhlng)</author>
		<pubDate>Sun, 05 Jun 2011 03:10:41 +0000</pubDate>
	</item>
</rss>
