<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_install_system fails inside shared library</title>
		<link>http://www.allegro.cc/forums/view/616333</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 14 Jun 2016 07:33:26 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I&#39;ve been writing a game engine for about six years now using Allegro as a back-end.</p><p>Lately I&#39;ve been upgrading the most recent version to use the various newer versions of C++, Visual Studio, and Allegro 5 <a href="https://github.com/cugone/Abrams2015">seen here</a>.</p><p>I&#39;ve been doing some internal testing by outputting a compiled library and then having simple sample games using said output.</p><p>However, for some reason, the call <span class="source-code"><a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a><span class="k2">(</span>ALLEGRO_VERSION_INT, std::atexit<span class="k2">)</span></span> returns false inside the function <span class="source-code">a2de_init<span class="k2">(</span><span class="k2">)</span></span> (Engine/a2de_base.cpp) when it is called from any of the sample games but not from the testing project for the library.</p><p>The documentation says nothing about what could cause the failure and only states: &quot;Don&#39;t call it inside a shared library unless you know what you are doing.&quot; This is not helpful. Why does it fail? Why shouldn&#39;t it be called inside a shared library? What must I know to do this correctly?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Thu, 09 Jun 2016 02:59:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not sure what the problem might be, but aren&#39;t you supposed to use AND instead of OR here?
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">bool</span> result <span class="k3">=</span> system_init_result <span class="k3">|</span><span class="k3">|</span> image_init_result <span class="k3">|</span><span class="k3">|</span>
        primitives_init_result <span class="k3">|</span><span class="k3">|</span> font_init_result <span class="k3">|</span><span class="k3">|</span> ttf_init_result <span class="k3">|</span><span class="k3">|</span>
        install_audio_result <span class="k3">|</span><span class="k3">|</span> acodec_init_result <span class="k3">|</span><span class="k3">|</span>
        native_dialog_init_result <span class="k3">|</span><span class="k3">|</span> install_keyboard_result <span class="k3">|</span><span class="k3">|</span>
        install_mouse_result <span class="k3">|</span><span class="k3">|</span> install_joystick_result<span class="k2">;</span>
</pre></div></div><p>

And you shouldn&#39;t need to call any of the al_uninstall* functions, Allegro uses <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> to have them called automatically.</p><p>APPEND:<br />There is some info about this here: <a href="http://allegro5.org/docs/html/refman/system.html">http://allegro5.org/docs/html/refman/system.html</a><br />The problem could be mismatched Allegro versions. And I&#39;m guessing that the data structure that <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> uses to store function pointers when called from a shared library will not be seen by the C runtime shutdown code in the executable, because they are using different instances of the C runtime. But maybe that&#39;s why you are calling the al_uninstall* functions manually.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 09 Jun 2016 03:37:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re right! Fixed. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Frustratingly enough (not the funny kind of frustrating), a previously-created sample game works just fine and their main functions, Property Sheets, and Property Managers are exactly the same...</p><p>Anyway, I&#39;ve &quot;fixed&quot; the problem by calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a><span class="k2">(</span>ALLEGRO_INT, std::atexit<span class="k2">)</span></span> just prior to the sample game&#39;s call to <span class="source-code">a2de::a2de_init<span class="k2">(</span><span class="k2">)</span></span>. It returns true when called from the game binary. Since the system is already installed <span class="source-code">a2de_init<span class="k2">(</span><span class="k2">)</span></span>&#39;s version always returns true.</p><p>An actual fix would be nice. More descriptive errors or documentation explaining why the system was not installed correctly would be great.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Thu, 09 Jun 2016 06:05:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you try doing what it says in the yellow box <a href="http://allegro5.org/docs/html/refman/system.html#al_init">here</a>? Allegro doesn&#39;t need the <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> pointer anyway, since you call the shutdown functions yourself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 09 Jun 2016 06:19:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Passing a <span class="source-code">nullptr <a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a> pointer</span> to <span class="source-code"><a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a></span> still returns false for the newer project.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Thu, 09 Jun 2016 21:57:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you sure your library and your game are using the same versions of allegro? That is the first thing that comes to mind when al_init fails.</p><p>Also, something to note about using al_install_system inside a dll is that the dll has its own entry and exit point separate from main&#39;s entry and exit point. If al_uninstall_system is running inside the dll&#39;s exit function it can cause problems with the main exit function, causing things to be destroyed twice. I&#39;ve run into that problem before.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 09 Jun 2016 23:05:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Yep, that was it.</p><p>The engine test project was using the dynamic versions of the Allegro library, but the actual Library project that outputs the static library for others to use was using the Monolithic version. Since each test game was using the dynamic versions of Allegro, there was a version mis-match.</p><p>Thanks guys.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Fri, 10 Jun 2016 00:38:42 +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/616333/1023206#target">Brooklyn</a> said:</div><div class="quote"><p>I&#39;ve been writing a game engine for about six years now using Allegro as a back-end.</p></div></div><p>

This and your avatar remind me of the <a href="https://www.allegro.cc/depot/CharredDirt/screenshots">Charred Dirt project</a> (R.I.P. forum) with <a href="https://www.allegro.cc/members/shadowfang/">ShadowFang</a>. You know him?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felix-The-Ghost)</author>
		<pubDate>Tue, 14 Jun 2016 01:51:41 +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/616333/1023280#target">Felix-The-Ghost</a> said:</div><div class="quote"><p>This and your avatar remind me of the Charred Dirt project (R.I.P. forum) with ShadowFang. You know him?</p></div></div><p>

Nope.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Brooklyn)</author>
		<pubDate>Tue, 14 Jun 2016 07:33:26 +0000</pubDate>
	</item>
</rss>
