<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Return code 1</title>
		<link>http://www.allegro.cc/forums/view/612485</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 27 Apr 2013 02:25:01 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>After my application ends, it returns 1 which should mean that something isn&#39;t right. However, I can&#39;t tell what it is.<br />Probably I am not freeing something correctly. In allegro.log I have the following text near the end:</p><p>d3d      D         d3d_disp.cpp:904  d3d_destroy_display_internals    [  41.01223] waiting for display 00327FF0&#39;s thread to end<br />d3d      W         d3d_disp.cpp:616  d3d_destroy_device               [  41.02325] d3d_destroy_device: ref count not 0<br />d3d      I         d3d_disp.cpp:1522 d3d_display_thread_proc          [  41.07369] d3d display thread exits</p><p>is this the cause that code 1 is returned? and if so, what is it caused by? I guess that something still referencing d3d device has to do with it. But what? Should I destroy all the bitmaps before destroying the allegro_display? or vice versa? and what about the fonts?<br />I am pretty sure that I eventually free everything. Should I care at all about this return code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 19:29:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you have a return statement in your main function?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Thu, 25 Apr 2013 19:45:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No. And it&#39;s void main() anyway. I guess allegro substitutes it for something and it&#39;s allegro&#39;s return code, not mine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 19:46:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Thu, 25 Apr 2013 19:47:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s funny here, Dizzy Egg?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 19:49:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What did you expect if you declare your main as void? A nice &#39;0&#39; to be returned??? <img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Thu, 25 Apr 2013 19:51:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><span class="k1">void</span> main</span> is invalid C/C++<span class="ref"><sup>[<a href="#">1</a>]</sup></span>.
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://stackoverflow.com/questions/204476/what-should-main-return-in-c-c">http://stackoverflow.com/questions/204476/what-should-main-return-in-c-c</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc ( Arvidsson)</author>
		<pubDate>Thu, 25 Apr 2013 19:52:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well. Thank you very much for noting that. I changed that.<br />However, i think it did return 0 in the past if all the threads had returned 0.<br />But the problem still stays: last thread returns 1. (I am not creating threads myself, these are all allegro threads). Should I worry about it?<br />--<br />I am pretty sure it&#39;s the d3d thread mentioned in the log.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 20:02:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s not the d3d thing, that&#39;s just a warning. You say you&#39;re seeing the return code of 1 in the debugger? What else does the debugger say? Is there a crash or an assertion or exception thrown?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Thu, 25 Apr 2013 20:06:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No. No crash and nothing is mentioned. That&#39;s why I went to allegro.log and that&#39;s the only thing that I found here which seemed abnormal.<br />Yes I see the return code in the debugger after everything ends.<br />By the way, it&#39;s pretty strange. Now I changed everything to the way you say it should be, with int main(int argc, char **argv) and ending with return 0.<br />But the funny thing is, the application still returns 1.</p><p>The thread 0x934 has exited with code 0 (0x0).<br />&#39;Mirrord.exe&#39; (Win32): Unloaded &#39;C:\Windows\SysWOW64\powrprof.dll&#39;<br />The thread 0x10f8 has exited with code 0 (0x0).<br />The thread 0xce8 has exited with code 1 (0x1).<br />&#39;Mirrord.exe&#39; (Win32): Unloaded &#39;C:\Windows\SysWOW64\nvd3dum.dll&#39;<br />&#39;Mirrord.exe&#39; (Win32): Unloaded &#39;C:\Windows\SysWOW64\d3d9.dll&#39;<br />&#39;Mirrord.exe&#39; (Win32): Unloaded &#39;C:\Windows\SysWOW64\d3d8thk.dll&#39;<br />No memory leaks detected.<br />Visual Leak Detector is now exiting.<br />The program &#39;[3456] Mirrord.exe&#39; has exited with code 1 (0x1).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 20:11:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How about putting a message box or a <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"bye\n"</span><span class="k2">)</span><span class="k2">;</span></span> just before that final <span class="source-code"><span class="k1">return</span> <span class="n">0</span></span>?  Does it show that message on exit?  Of course you&#39;d have to run it from a console to see a printf.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Apr 2013 20:15:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m pretty sure it runs up to the very end and executes every last line.<br />But I did what you asked. Yes, the message is shown.</p><p>UPDATE: I attached allegro.log to the first post.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Thu, 25 Apr 2013 20:19:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could be a signal handler called &quot;on exit&quot; because a SIGSEGV happens for example and/or something installed by atexit() crashes. Can you try putting a breakpoint on libc&#39;s exit() ? If something is calling exit(1), you&#39;d see in the call stack.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 25 Apr 2013 23:54:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello, Audric and thank you for your input.<br />Could you explain to me, how do I put a breakpoint on libc&#39;s exit?</p><p>UPDATE: OK, I did it this way: I made an empty function, put a breakpoint on it and then passed it to atexit().<br />The strange thing is that when I check value of the argument &quot;code&quot; of the exit(int code) function, which is up the call stack, it shows 0 in the debugger. Up to the end. And then visual studio says it exited with code 1...</p><p>I&#39;m not sure I put the breakpoint when you suggested, though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 26 Apr 2013 00:24:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try setting a breakpoint anywhere after your program starts up fully. Check which threads are running (don&#39;t know how in VS, but should be possible.) Not their id/address and what they&#39;re doing. Then when the app exits check which thread that returns 1 corresponds to the one you checked on earlier.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 26 Apr 2013 02:46:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your test already shows that the issue happens after main() returns, after it executes the function you hooked on atexit(). Maybe then it executes another atexit() function that was registered before yours (by a library, usually). <br />I don&#39;t know about Visual Studio&#39;s debugger for C language, though if it has similar options as for C#, be sure to check in Debug/Exception menu: &quot;Break on ...&quot; everything : signals, caught exception, uncaught exception, runtime errors... everything it proposes.<br />If you do find a way to make it break on system functions of your choice, try stopping abort() in addition to exit().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 26 Apr 2013 02:47:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>Trent Gamblin</b><br />I have the following threads:</p><p>2928	0	Main Thread	name: Mirrord.exe!MirrorApp::Init	Normal</p><p>5676	0	Worker Thread	name: GdiPlus.dll!DllRefCountSafeThreadThunk()	location: GdiPlus.dll!BackgroundThreadProc	Normal</p><p>1556	0	Worker Thread	name: msvcr110d.dll!_threadstartex	location: allegro-5.0.8-monolith-md-debug.dll!501c453e	Normal</p><p>5684	0	Worker Thread	name: nvd3dum.dll thread	location: nvd3dum.dll!67319d84	Above Normal</p><p>When the program ends, the 0x162c thread returns with code 1, that is the second thread 5676.</p><p><b>Audric</b><br />The problem is, the return code 0 stays up to the end. I mean, I step through the whole program up to the line <span class="source-code">__crtExitProcess<span class="k2">(</span>code<span class="k2">)</span><span class="k2">;</span></span> after which the program ends. And even there it shows &quot;the program exited with code 1&quot;, when I step over the program ends with code 1. I can&#39;t step into this function itself thought I get thrown into assembly. <br />How is that even possible? Could it be some memory corruption?<br />I have no idea what else to enable, I think it should break at every exception.<br />I think I found a way to break at function by its name, and I added breakpoints on abort and exit functions, but it doest break on abort. It breaks on exit, though.</p><p>UPDATE:<br />It seems that the application returns 1 when the last thread returns 1. If the last thread to end isn&#39;t this GDI thread, then I get return code 0.<br />Moreover, I just used this tutorial <a href="http://wiki.allegro.cc/index.php?title=Basic_tutorial_on_loading_and_showing_images">http://wiki.allegro.cc/index.php?title=Basic_tutorial_on_loading_and_showing_images</a> and the GDI thread there also returns 1. However, the application itself returns what it is told to return.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 26 Apr 2013 11:01:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you set a breakpoint in _al_shutdown_gdiplus? What happens if you don&#39;t init the image addon?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 26 Apr 2013 20:21:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If I don&#39;t init the image addon the return code is 0.<br />Yes, I can put a breakpoint there. What am I looking for over there? </p><p><span class="source-code">Gdiplus::GdiplusShutdown<span class="k2">(</span>gdiplusToken<span class="k2">)</span><span class="k2">;</span></span></p><p>the gdiplusToken is 37445138
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 26 Apr 2013 20:43:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure why the GdiPlus thread is returning 1. A temporary solution might be to call al_shutdown_image_addon before returning from main.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 26 Apr 2013 20:48:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Shutting image addon down manually doesn&#39;t kill the gdi thread and it still only gets destroyed at exit (with code 1). Maybe some other addon uses it too?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 26 Apr 2013 21:06:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What about a patch like this?</p><div class="source-code snippet"><div class="inner"><pre>diff <span class="k3">-</span><span class="k3">-</span>git a<span class="k3">/</span>addons<span class="k3">/</span>image<span class="k3">/</span>iio.c b<span class="k3">/</span>addons<span class="k3">/</span>image<span class="k3">/</span>iio.c
<a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> d98716e..6ecbfe5 <span class="n">100644</span>
<span class="k3">-</span><span class="k3">-</span><span class="k3">-</span> a<span class="k3">/</span>addons<span class="k3">/</span>image<span class="k3">/</span>iio.c
<span class="k3">+</span><span class="k3">+</span><span class="k3">+</span> b<span class="k3">/</span>addons<span class="k3">/</span>image<span class="k3">/</span>iio.c
@@ <span class="k3">-</span><span class="n">128</span>,<span class="n">6</span> <span class="k3">+</span><span class="n">128</span>,<span class="n">10</span> @@ <span class="k1">bool</span> <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
 <span class="k1">void</span> <a href="http://www.allegro.cc/manual/al_shutdown_image_addon"><span class="a">al_shutdown_image_addon</span></a><span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
 <span class="k2">{</span>
    iio_inited <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="k3">+</span>
<span class="k3">+</span>#ifdef ALLEGRO_CFG_IIO_HAVE_GDIPLUS
<span class="k3">+</span>   _al_shutdown_gdiplus<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k3">+</span>#endif
 <span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Fri, 26 Apr 2013 22:03:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll probably have to compile allegro myself for that, right? or I could just place shutdown_gdi myself in my code?<br />Anyway, thank you very much, Trent. It seems it&#39;s nothing serious I should care about.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aikei_c)</author>
		<pubDate>Fri, 26 Apr 2013 23:00:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can try calling _al_shutdown_gdiplus() yourself (you may have to declare it.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sat, 27 Apr 2013 00:29:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/612485/981630#target">Aikei_c</a> said:</div><div class="quote"><p>It seems it&#39;s nothing serious I should care about.</p></div></div><p>
This could be the tip of the iceberg in a allegro bug, so thank you for your persistence.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Sat, 27 Apr 2013 02:25:01 +0000</pubDate>
	</item>
</rss>
