<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Display lost/found events are never fired</title>
		<link>http://www.allegro.cc/forums/view/609234</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 10 Jan 2012 23:58:56 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi there,</p><p>I did post the <a href="http://www.allegro.cc/forums/thread/606904">same question</a> a year ago, tho did not get any replies then. I am eager to tackle the same problem once again.</p><p>So, has anyone successfully implemented a Direct3D allegro display with ALLEGRO_NO_PRESERVE_TEXTURE bitmaps?</p><p>My issue is that display lost/found events are never fired (display event source is registered in event queue, can confirm this as I am getting display expose events).</p><p>Is it possible that video card drivers are affecting this?</p><p>(Testing on Windows 7 using Allegro 5.0.5)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Sun, 08 Jan 2012 17:13:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That sounds strange. I&#39;m pretty sure this works for other people. Could you show us the code your using? Or better yet, an absolute minimal example that still has this problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 08 Jan 2012 18:24:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Thomas,</p><p>I can&#39;t really post the full code as it spans multiple classes, but here is a pseudo excerpt:</p><p><b>1.</b> Event queue:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> eventQueue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_event_queue"><span class="a">al_create_event_queue</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<b>2.</b> Display setup:
</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="c">// Allegro bitmap setup</span>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_ARGB_8888<span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/al_add_new_bitmap_flag"><span class="a">al_add_new_bitmap_flag</span></a><span class="k2">(</span>ALLEGRO_VIDEO_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span><a href="http://www.allegro.cc/manual/al_add_new_bitmap_flag"><span class="a">al_add_new_bitmap_flag</span></a><span class="k2">(</span>ALLEGRO_NO_PRESERVE_TEXTURE<span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="c">// Display options and flags</span>
<span class="number">  7</span><a href="http://www.allegro.cc/manual/al_set_new_display_option"><span class="a">al_set_new_display_option</span></a><span class="k2">(</span>ALLEGRO_VSYNC, <span class="n">0</span>, ALLEGRO_SUGGEST<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="k1">int</span> displayFlags <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 10</span>displayFlags <span class="k3">|</span><span class="k3">=</span> ALLEGRO_DIRECT3D<span class="k2">;</span>
<span class="number"> 11</span>displayFlags <span class="k3">|</span><span class="k3">=</span> ALLEGRO_GENERATE_EXPOSE_EVENTS<span class="k2">;</span>
<span class="number"> 12</span>displayFlags <span class="k3">|</span><span class="k3">=</span> ALLEGRO_WINDOWED<span class="k2">;</span>
<span class="number"> 13</span>displayFlags <span class="k3">|</span><span class="k3">=</span> ALLEGRO_RESIZABLE<span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span><a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>displayFlags<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">400</span>, <span class="n">400</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

<b>3.</b> Display event source registration:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>eventQueue, <a href="http://www.allegro.cc/manual/al_get_display_event_source"><span class="a">al_get_display_event_source</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<b>4.</b> Bitmaps are created (not using any custom formats or flags, but default as defined above)</p><p><b>5.</b> Event loop:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> event<span class="k2">;</span>

<span class="k1">while</span> <span class="k2">(</span><span class="k1">true</span><span class="k2">)</span> <span class="k2">{</span>

  <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>eventQueue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>

  <span class="k1">if</span> <span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_DISPLAY_FOUND<span class="k2">)</span> <span class="k2">{</span>
    <span class="c">// Never reported (same for ALLEGRO_EVENT_DISPLAY_LOST)</span>
  <span class="k2">}</span>
  <span class="c">// Other events</span>
  <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>...<span class="k2">)</span> <span class="k2">{</span>

  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

I can see that the bitmaps loose their textures if I resize display window, so at least ALLEGRO_NO_PRESERVE_TEXTURE seems to work as expected. However, the trouble is I never get lost/found events and that makes it a bit of a challenge to know when you need to re-create them.</p><p><b>Edit:</b> I am also using VS2010 allegro static lib binaries from allegro.cc if that matters somehow?</p><p><b>Edit 2:</b> My application is single-threaded.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Sun, 08 Jan 2012 22:01:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you make an absolute minimal example that shows this problem? Something that is compilable and works?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 08 Jan 2012 23:58:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Thomas,</p><p>Thanks for helping me with this problem. I did create a very-minimal Visual C++ 2010 project illustrating the problem (attached).</p><p>There is a pre-compiled release EXE for testing (statically linked so there shouldn&#39;t be any dependencies for running). The code is in &quot;main.cpp&quot;.</p><p>The program will pretty much do all the steps as in my post above, except it will also draw a blue bitmap with a timer. Display resize/lost/found events are sent to console.</p><p>Now on my laptop (late 2008 Macbook NVIDIA GeForce 9400M with bootcamp Windows 7 32-bits) display lost/found events are never reported (I have included a couple of screenshots in the attached ZIP to illustrate this).</p><p>Simas
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 01:39:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here it&#39;s reporting some lost/found events but not on minimize. If I press Ctrl+Alt+Delete it does show the lost and found events. So I&#39;m not sure why minimize isn&#39;t causing the events...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 10 Jan 2012 02:24:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just tested the same executable on a different machine (Windows 7 64-bits on NVIDIA GeForce 460 GTX) - and no lost/found events are reported there too.</p><p>Trent, what OS and video card have you got?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 02:58:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t get any lost/found event with your test. All I get are resize events if I resize, minimize, maximize or restore after maximize. No resize event if I restore a minimized Window. After I do any of those actions, the blue rectangle doesn&#39;t draw any more, and in its place there are a few random coloured pixels.</p><p>On a side note, the window border is horrendously thick.</p><p>I have an HD 6950 running Windows 7 64 bit.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Tue, 10 Jan 2012 03:38:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Oscar, that is exactly my issue here. Apparently others are receiving lost/found events and I suspect that this could somehow be related to Windows 7 (as the events now seem to missing on both NVIDIA and AMD cards/drivers).</p><p>(The thing with an image turning into a random colored pixel junk is a result of ALLEGRO_NO_PRESERVE_TEXTURE flag, which is what we are basically testing here and is expected behavior)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 03:49:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was using Windows 7 64 bit. Did you try ctrl+alt+delete? I looked at the code and the lost/found detection looks like it&#39;s made so that the reason doesn&#39;t matter, so the events should be firing no matter what the cause. It&#39;s easy to hook minimize/maximum and fire the events there too but I&#39;d like to know if that&#39;s normal behaviour or if the d3d code is broken. There may be more info on MSDN.</p><p>EDIT: Also I&#39;m using 5.1. Could be that a fix wasn&#39;t backported to 5.0.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 10 Jan 2012 04:07:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Trent,</p><p>I tried with Ctrl+Alt+Delete - still no good, no lost/found events here.<br />As for using 5.1 - what do you mean? I have statically linked allegro 5.0.5 into provided EXE binary.</p><p>Since you are on Windows 7 as well, I am a bit lost. Could any Allegro developers look into this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 04:17:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I compiled your program myself using 5.1... and I am an Allegro developer <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 10 Jan 2012 04:52:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alright, that means I am in good hands and at the right place <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p><b>Update:</b> Built allegro 5.1 from the latest SVN 5.1 branch and re-compiled my test program using the new lib, results:</p><p>- When re-sizing I am still getting no lost/found events, however the ctrl+alt+del switch will now generate a lost and found event (and that never happened with 5.0.5). So at least something did change there for 5.1 branch, but it&#39;s still bugged.</p><p>(I have also attached just that new EXE linked with allegro 5.1).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 05:44:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>With the new exe now it generates the lost/found event with Ctrl+Alt+And, but the blue rectangle gets lost still.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Tue, 10 Jan 2012 06:33:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s expected Oscar, when using the ALLEGRO_NO_PRESERVE_TEXTURE flag with D3D. Except the part about not getting lost/found events on minimize. I&#39;ll try my best to look into it tomorrow after my regular work routine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 10 Jan 2012 08:55:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Trent, just to make clear - the events are also missing when re-sizing a window. Actually, is it normal for the Direct3D device to be lost just by re-sizing a window? I always thought you need something more serious for this to happen (a fullscreen switch or an alt-tab).</p><p>An excerpt from MSDN:</p><div class="quote_container"><div class="title"><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174714(v=VS.85).aspx">Lost Devices (Direct3D 9)</a> said:</div><div class="quote"><p>
By design, the full set of scenarios that can cause a device to become lost is not specified. Some typical examples include loss of focus, such as when the user presses ALT+TAB or when a system dialog is initialized. Devices can also be lost due to a power management event, or when another application assumes full-screen operation. In addition, any failure from IDirect3DDevice9::Reset puts the device into a lost state.</p></div></div><p>

E.g. nothing is mentioned even close to a simple window resize.</p><p>And do you think it&#39;s feasible to expect this fix in a stable 5.0 branch? (As I understand 5.1 is still not going to go stable any time soon).</p><p>Thanks again for looking into this,</p><p>Simas
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 10 Jan 2012 14:01:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, it&#39;s not true that a device is &quot;lost&quot; on resize. Really it&#39;s not lost, it&#39;s manually recreated by Allegro though which has the same effect. Allegro does this so that the backbuffer is resized correctly, otherwise you&#39;d get odd stretched disproportionate views. So ya, it needs to generate lost+found events when these things happen because the code now only checks for actual lost/found events from D3D like alt-tab out of fullscreen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 10 Jan 2012 21:30:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Probably the same as everyone else, but I get resize events on resizing and minimise/maximise and a display found on coming back from ctrl-alt-delete. minimising/maximising loses the rectangle to be replaced by a couple of random pixels (probably caused by the video bitmap being lost)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Tue, 10 Jan 2012 23:58:56 +0000</pubDate>
	</item>
</rss>
