<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>TTF Loading Failing</title>
		<link>http://www.allegro.cc/forums/view/617368</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 13 Apr 2018 20:34:36 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello Everybody !<br />I&#39;m new to Allegro Programming (and programming in general <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> ) and i get an error i don&#39;t even know the meaning of <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /></p><p>I Just want to make a &quot;Hello World&quot; test program, everything works fine, until i try to load a ttf font (it worked with the builtin font).</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="number">  2</span><span class="p">#include &lt;iostream&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;string&gt;</span>
<span class="number">  4</span><span class="p">#include "allegro.h"</span>
<span class="number">  5</span><span class="p">#include "allegro_color.h"</span>
<span class="number">  6</span><span class="p">#include "allegro_font.h"</span>
<span class="number">  7</span><span class="p">#include "allegro_ttf.h"</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span>
<span class="number"> 10</span><span class="k2">{</span>
<span class="number"> 11</span>    <span class="k1">bool</span> allegroIsWorking <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <span class="k1">bool</span> alfontIsWorking <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k1">bool</span> alTTFIsWorking <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <span class="k1">if</span><span class="k2">(</span>allegroIsWorking <span class="k3">&amp;</span><span class="k3">&amp;</span> alfontIsWorking <span class="k3">&amp;</span><span class="k3">&amp;</span> alTTFIsWorking<span class="k2">)</span>
<span class="number"> 15</span>    <span class="k2">{</span>
<span class="number"> 16</span>        cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"It Works\n"</span><span class="k2">;</span>
<span class="number"> 17</span>    <span class="k2">}</span>
<span class="number"> 18</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span> Ecran <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">1000</span>,<span class="n">500</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span> <a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"Roboto-Bold.ttf"</span>,<span class="n">70</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>    <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>    <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>,<a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">2</span>,<span class="n">2</span>,<span class="n">0</span>,<span class="s">"Hello world"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>    <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>        
<span class="number"> 24</span>    
<span class="number"> 25</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 26</span><span class="k2">}</span>
</div></div><p>

There are no compilation errors.<br />The TTF file &quot;Roboto-Bold.ttf&quot; is in the program folder.<br />When i use &quot;al_create_builtin_font&quot; instead of &quot;al_load_ttf_font&quot; it works perfectly.<br />At runtime, the debug console displays &quot;It Works&quot; and creates the display before crashing.<br />The crash message displayed in the console is:</p><p>Assertion failed!</p><p>Program: C:\Users\PathToMyProgam\program.exe<br />File: C:/dev/allegro_winpkg/universal/allegro/addons/font/text.c, Line 79</p><p>Expression: font</p><p>Please, can someone tell me what messes everything up ? <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /> <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /> <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /><br />2 hours i&#39;ve been trying to solve this without success <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><p>Thank you very much !!!</p><p>Edit:<br />After &quot;al_laod_ttf_font&quot; font pointer is null, so it means it doesn&#39;t find the font, but i double checked and the ttf file is in the exe folder... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /><img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /><br />Any ideas ?</p><p>Edit Edit:<br />I found the problem, but its still really really weird:</p><p>I use code::blocks, and when i run the program from code::blocks, it crashes.<br />But, when i run the program directly from the .exe file in the bin/debug folder of my project... IT WORKS !</p><p>I actually have no idea what caused this bug tho, and i would be interested if someone had an idea <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mumu1000)</author>
		<pubDate>Fri, 13 Apr 2018 16:30:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Short answer - check the current working directory.</p><p>Long answer - change the directory to the one where your executable is, and THEN load your font.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 13 Apr 2018 19:10:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you very much !<br />Its weird the working directory isnt the good one by default...</p><p>Have a good day ^^
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mumu1000)</author>
		<pubDate>Fri, 13 Apr 2018 20:29:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The working directory is where ever you ran the program from. There&#39;s a setting in CB that lets you change the executable&#39;s current working directory. </p><p><span class="remote-thumbnail"><span class="json">{"name":"611416","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/a\/ea1a752635f9cb273e082b13c8ff3b99.png","w":877,"h":747,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/a\/ea1a752635f9cb273e082b13c8ff3b99"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/a/ea1a752635f9cb273e082b13c8ff3b99-240.jpg" alt="611416" width="240" height="204" /></span></p><p>However, that doesn&#39;t stop users running your program outside of CB. For that you need to fix the current working directory. You can do this pretty easily with Allegro 5.</p><div class="source-code snippet"><div class="inner"><pre>ALLEGRO_PATH<span class="k3">*</span> p <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_standard_path"><span class="a">al_get_standard_path</span></a><span class="k2">(</span>ALLEGRO_EXENAME_PATH<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>p<span class="k2">)</span> , ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_destroy_path"><span class="a">al_destroy_path</span></a><span class="k2">(</span>p<span class="k2">)</span><span class="k2">;</span>
p <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 13 Apr 2018 20:34:36 +0000</pubDate>
	</item>
</rss>
