<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Game not working with warning log enabled</title>
		<link>http://www.allegro.cc/forums/view/618411</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 21 May 2021 16:21:19 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have only just discovered how to enable Allegro logging within my game - I must have missed that part of the docs when I read them originally. I just had a problem with my game which required me to set up logging. I previously didn&#39;t have an allegro.cfg file.</p><p>What I&#39;m finding now is that with the trace level set to &#39;warn&#39;, the game is not playable. It starts up without any music on the main menu, then it freezes the moment I try to play a sound effect.</p><p>This is what I see if I break into it:</p><p>    al_attach_sample_instance_to_mixer(instance,mixers[Category::SFX]);<br />--&gt; al_set_sample_instance_playing(instance, true);</p><p>I also find that the game takes forever to start up if the trace level is set to &#39;info&#39;, because it tries dozens of display formats and waits 10 seconds between each one (d3d_create_display_internals - WaitForSingleObject(params.AckEvent, 10*1000)) - it&#39;s unclear from the code why the trace level affects this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Sat, 08 May 2021 21:19:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yikes, that doesn&#39;t sound good. How do you enable the tracing, just via the system config/allegro5.cfg? Are you using any multithreading?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 10 May 2021 13:06:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, by changing the trace level in allegro.cfg. There are threads for fading out sound effects, and for music.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Mon, 10 May 2021 15:04:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Eagle logging is thread safe. You could pipe allegro output to Eagle, and get a sane log back.</p><p>Scratch that. Deadlock in window creation. That&#39;s odd. My MSAA test program freezes waiting forever for a signal from the d3d_display_thread_proc, which is never launched, and the thread is never created to acknowledge it.</p><p>That&#39;s in DEBUG mode with all logging piped to EagleLog(), which is thread safe. It stops after enumerating formats, and trying to create the first one, in d3d_create_display_internal. It waits forever for the thread to signal.</p><p>It runs a detached thread to run d3d_display_thread_proc, which would send the signal to ACKnowledge the event.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 11 May 2021 02:10:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I suppose it&#39;s possible that our logging has bad performance/race conditions in a multi-threaded context (not obviously though, we have mutexes and such). Could try using <span class="source-code">al_register_trace_handler</span> to set an empty handler and see if that helps.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 11 May 2021 07:46:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Detached threads aren&#39;t protected by a CriticalSection any longer after al_run_detached_thread calls al_thread_detach.</p><p>If that matters. Also, the return value of beginthreadex is being ignored.</p><p>Also, my code is hanging with one thread waiting on ConsoleOutputW</p><p><b>EDIT</b><br />If I use allegro5.cfg and set trace to &#39;debug&#39; or &#39;info&#39; it hangs trying to create the display thread. If I set trace to &#39;warn&#39; it hangs later, and if I set trace to &#39;none&#39; it works fine.</p><p><b>EDIT2</b><br />Allegro is hanging in an ALLEGRO_INFO call during a call to _al_mutex_lock on line 245 of src/debug.c.</p><p>Why would allegro locking its own private mutex cause a deadlock in my code? It should lock allegro&#39;s log mutex and then lock my logging mutex in EagleLog() and output normally.</p><p><b>EDIT3</b><br />After some debugging, I discovered that the CRITICAL_SECTION used by allegro&#39;s log handler is owned by the MAIN thread.</p><p>I tried to fix it by adding in an _al_mutex_unlock call but nothing changed.</p><p>al_trace_suffix is missing a mutex unlock call when a user trace handler is being used.</p><p>However, the CRITICAL_SECTION is still messed up. When I print it out in GDB before the call to al_trace_prefix completes, these are the values it holds :
</p><pre>
(gdb) p *(trace_info.trace_mutex.cs)
$1 = {DebugInfo = 0xffffffff, LockCount = -2, RecursionCount = 176, OwningThread = 0x4750, LockSemaphore = 0x0, SpinCount = 33556432}
</pre><p>
Thread 0x4750 is MAIN, and Allegro is inside its own thread when it calls the allegro trace handler. The lock on the critical section shouldn&#39;t be held at all, and the recursion count indicates something is really wrong.</p><p>It took me all morning just to figure that out, and my fix doesn&#39;t work to lessen the recursion count or the lock held by main.</p><p><b>UPDATE</b><br />My fix DOES work, at least for my problem. I was linking to an old version of allegro.</p><p>Here&#39;s a patch to fix the resource leak :</p><pre>
--- C:/Users/Marc/AppData/Local/Temp/TortoiseGit/debug-619c69e3.002.c   Thu May 13 11:18:03 2021
+++ E:/usr/libs/Allegro52X/src/debug.c  Wed May 12 11:20:57 2021
@@ -300,6 +300,7 @@
    if (_al_user_trace_handler) {
       _al_user_trace_handler(static_trace_buffer);
       static_trace_buffer[0] = &#39;\0&#39;;
+      _al_mutex_unlock(&amp;trace_info.trace_mutex);
       return;
    }
</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 13 May 2021 21:21:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Edgar, this is now <a href="https://github.com/liballeg/allegro5/commit/679f0774cafd6390a6900476bde71f84161a7fbd">fixed</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 15 May 2021 12:37:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As well, the flickering problem should be fixed by your patch too. That doesn&#39;t explain the long startup problem the OP is having though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 15 May 2021 23:00:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I updated to the latest Allegro and I&#39;m not seeing the delay issue any more (although I may have changed something else).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Gillett)</author>
		<pubDate>Fri, 21 May 2021 16:21:19 +0000</pubDate>
	</item>
</rss>
