<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_load_ttf_font_f crash</title>
		<link>http://www.allegro.cc/forums/view/609159</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 31 Dec 2011 03:18:10 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre>    <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>memfile <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_open_memfile"><span class="a">al_open_memfile</span></a><span class="k2">(</span>buffer, file_size, <span class="s">"rb"</span><span class="k2">)</span><span class="k2">;</span>

    std::string fn <span class="k3">=</span> file_name<span class="k2">;</span>
    fn.append<span class="k2">(</span>file_type<span class="k2">)</span><span class="k2">;</span>

    f <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font_f"><span class="a">al_load_ttf_font_f</span></a><span class="k2">(</span>memfile, fn.c_str<span class="k2">(</span><span class="k2">)</span>, size, flags<span class="k2">)</span><span class="k2">;</span>

    <span class="c">//al_fclose(memfile);</span>
</pre></div></div><p>

Note that I have commented out al_fclose(memfile);<br />This way it doesn&#39;t crash. However, if I close the memfile, it will crash as soon as the game has to draw some text using the loaded font.</p><p><a href="http://www.allegro.cc/manual/5/al_load_ttf_font_f">http://www.allegro.cc/manual/5/al_load_ttf_font_f</a><br />says:<br />Note: The file handle is owned by the returned ALLEGRO_FONT object and must not be freed by the caller, as FreeType expects to be able to read from it at a later time.</p><p>To my understanding, the note says that I am not supposed to free <b>buffer</b>.</p><p>So do I get it right - I must not al_fclose the memfile and I must not al_free the buffer?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hyena_)</author>
		<pubDate>Sat, 31 Dec 2011 02:55:55 +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/609159/941953#target">Hyena_</a> said:</div><div class="quote"><p> So do I get it right - I must not al_fclose the memfile and I must not al_free the buffer?</p></div></div><p>Right.</p><p>Of course, you must still free the memory after you destroy the font. (Check the source to see if it closes the file for you.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 31 Dec 2011 03:00:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks. Do I have to al_fclose the memfile too after having freed the memory?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hyena_)</author>
		<pubDate>Sat, 31 Dec 2011 03:04:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>you want to close it before freeing the memory I think.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 31 Dec 2011 03:18:10 +0000</pubDate>
	</item>
</rss>
