<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_draw_textf causing crash</title>
		<link>http://www.allegro.cc/forums/view/618663</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 24 May 2022 02:11:00 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi,<br />    having a problem with al_draw_textf. I&#39;m using it and if I comment it out<br />the program works fine.</p><p>I&#39;ve initialised the font addon and the ttf font addon.</p><p>Here&#39;s the output on the windows console.</p><div class="source-code snippet"><div class="inner"><pre>Telling user how many files are needed <span class="k1">for</span> <span class="k1">this</span> task.
There is more than <span class="n">1</span> file needed.
IO-&gt;font value is <span class="n">0x266e1a0</span>
<a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> is <span class="n">1920</span>
<a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span> is <span class="n">960</span>
data.num_files_needed <span class="k3">=</span> <span class="n">2</span>
ALLEGRO_ALIGN_CENTRE is <span class="n">1</span>
</pre></div></div><p>

The code in the program is :</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="k1">if</span><span class="k2">(</span>data.num_files_needed <span class="k3">=</span><span class="k3">=</span> <span class="n">1</span><span class="k2">)</span>
<span class="number">  2</span>        <span class="k2">{</span>  
<span class="number">  3</span>          <span class="p">#ifdef LOAD_FILES_PROMPT_USE_COUT</span>
<span class="number">  4</span>           cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"There is 1 file needed."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number">  5</span>        <span class="p">#endif</span>
<span class="number">  6</span>            <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span> IO-&gt;font, WHITE, <a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span>, <span class="n">720</span>, ALLEGRO_ALIGN_CENTRE, <span class="s">"1 file is needed for this task."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>        <span class="k2">}</span>
<span class="number">  8</span>        <span class="k1">else</span>
<span class="number">  9</span>        <span class="k2">{</span>
<span class="number"> 10</span>      <span class="p">#ifdef LOAD_FILES_PROMPT_USE_COUT</span>
<span class="number"> 11</span>         <span class="k1">if</span><span class="k2">(</span>IO-&gt;font <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 12</span>         <span class="k2">{</span>
<span class="number"> 13</span>          cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"IO-&gt;font is NULL."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 14</span>         <span class="k2">}</span>
<span class="number"> 15</span>         <span class="k1">if</span><span class="k2">(</span>IO-&gt;display <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<span class="number"> 16</span>         <span class="k2">{</span>
<span class="number"> 17</span>          cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"display is NULL."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>          
<span class="number"> 18</span>         <span class="k2">}</span>
<span class="number"> 19</span>      
<span class="number"> 20</span>           cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"There is more than 1 file needed."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 21</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"IO-&gt;font value is "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> IO-&gt;font <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 22</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_get_display_width(IO-&gt;display) is "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 23</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"al_get_display_width(IO-&gt;display) / 2 is "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 24</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"data.num_files_needed = "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> data.num_files_needed <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 25</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"ALLEGRO_ALIGN_CENTRE is "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> ALLEGRO_ALIGN_CENTRE <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 26</span>        <span class="p">#endif</span>
<span class="number"> 27</span>      
<span class="number"> 28</span>            <a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span> IO-&gt;font, WHITE, <a href="http://www.allegro.cc/manual/al_get_display_width"><span class="a">al_get_display_width</span></a><span class="k2">(</span>IO-&gt;display<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span>, <span class="n">720</span>, ALLEGRO_ALIGN_CENTRE, <span class="s">"%d files are needed for this task."</span>, data.num_files_needed <span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 29</span>      <span class="p">#ifdef LOAD_FILES_PROMPT_USE_COUT</span>
<span class="number"> 30</span>         cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Called al_draw_textf."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 31</span>      <span class="p">#endif</span>
<span class="number"> 32</span>        <span class="k2">}</span>
</div></div><p>

I&#39;ve been trying to find out the reason it doesn&#39;t crash with al_draw_textf commented out to no avail <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Can someone help?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Mon, 16 May 2022 15:54:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Windows or linux?</p><p>Run in debug mode (for linux use GDB) and see what the actual crash reason is. That way you know if it&#39;s a dead pointer, or whatever. Also if there&#39;s an allegro log, read that.</p><p>Double verify that font is loaded, pointing to a real font, and that the code you gave us is exactly the code that shows the problem.</p><p>Check if a different font works, maybe you have some sort of corrupted font file and Allegro doesn&#39;t catch it.</p><p>for linux, debugging is as easy as:
</p><div class="source-code snippet"><div class="inner"><pre>gdb .<span class="k3">/</span>myprogram
run
<span class="k2">[</span>it will crash<span class="k2">]</span>
bt      <span class="k2">[</span><span class="s">"backtrace"</span><span class="k2">]</span>
</pre></div></div><p>
That&#39;ll show the function it died in, and what exact line of code it died on.</p><p>If you type &quot;list&quot; it&#39;ll show ten lines of code around where it crashed.</p><p>If it&#39;s windows, visual studio (or mingw or whatever) have their debuggers too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Mon, 16 May 2022 18:41:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks.</p><p>Windows.</p><p>I tried with a different font and the same crash happened.</p><p>I made a debug version, ran it in gdb and the problem didn&#39;t happen.</p><p>I noticed I&#39;d not used the -g flag on one of the object files so I sorted that<br />out, ran the program in gdb from the command line and gdb didn&#39;t work.</p><p>Tried again and it worked but the problem again wasn&#39;t there.</p><p>I had the idea of running the debug version program from the icon for it in exporer and that worked too.</p><p>I thought well at least I can use my program now.</p><p>I then changed the Makefile back to how it was, built the non-debug version and it seems to be working.</p><p>I&#39;m totally baffled <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> but I&#39;m not complaining.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Mon, 16 May 2022 19:59:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is the font loaded correctly? <br />There is a value for font, but is it valid?</p><p>Have you tried putting in al_draw_text instead to see if it will print at all
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Mon, 16 May 2022 21:14:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Possibilities :<br />1) The font has been destroyed, but not zeroed out. This is known as a dangling pointer. It appears valid, but points to deallocated memory.</p><p>2) The current working directory is wrong. You can tell this by running it from a command console in the directory of the executable.</p><p>3) Try an absolute path to diagnose 2). If it works, the cwd is wrong.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 16 May 2022 21:28:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Many thanks for the replies.</p><p>I load the font and then check the pointer isn&#39;t NULL. The arguments I pass to </p><p>al_load_ttf_font are valid. I don&#39;t know any other way to load the font. Seems proper to me.</p><p>I check the value of the pointer when it&#39;s loaded and it&#39;s the same value just before the crash.</p><p>Also, al_draw_text is called just before the code I posted and it works fine.</p><p>There&#39;s no call to al_destroy_font anywhere in the program.</p><p>The program works now though and I&#39;ve no idea why there was a problem or what fixed it (assuming my program is really working).</p><p>If it&#39;s alright with everyone, I&#39;ll get on with the programming and put it down to a mystery.</p><p>Thanks very much for all the help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Mon, 16 May 2022 23:44:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m always terrified when something fixes <b>*and I don&#39;t know why</b>* because it could happen again.</p><p>Definitely run a debugger when it crashes so you know the exact line of code (it will also include inside the Allegro code).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 17 May 2022 06:46:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>..and guess what, it has. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Tue, 17 May 2022 23:58:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it changes randomly when you change random lines of code. It&#39;s often a pointer problem and it is or isn&#39;t breaking depending on where the compiler laid out the memory of your variables (and the pointer is, or isn&#39;t touching one of them).</p><p>Run that debugger!!!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Wed, 18 May 2022 00:13:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Before you go running it through a debugger. Post Code, and check that your runtime library version is the same as the header version you&#39;re using for Allegro 5.</p><p>A mismatched dll could randomly barf.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 18 May 2022 01:06:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d already run that Debugger before I read the last two posts. I had the same problem as before i.e the problem didn&#39;t happen with the debugger.</p><p>Although I know that when I&#39;m sure, I&#39;m probably wrong, I nonetheless can&#39;t see how the lib files could be being used with the wrong headers as I&#39;m using Siegelords 5.7.2 binaries and deps. The only thing that makes me doubt this is that I&#39;ve seen<br />that al_is_ttf_font_initialised() is in the online manual, but I got errors when trying to use it despite havin both allegro_font.h and allero_ttf_font.h included.</p><p>Anyway, I&#39;ve posted the entire project.</p><p>I&#39;m anticipating being told I&#39;m doing some very unnecessary things.I know it could all be simpler. It&#39;s just the way I work - I work out the way it aught to be done after doing something silly.</p><p>But say whatever.</p><p>Thanks for your perseverence.</p><p>I can&#39;t upload. Waiting to see if I can after I&#39;d posted.</p><p>I&#39;ve tried uploading the project but can&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 18 May 2022 02:53:21 +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/618663/1052324#target">William Labbett</a> said:</div><div class="quote"><p> I can&#39;t upload. Waiting to see if I can after I&#39;d posted.</p></div></div><p>Maybe a repo or a gists might work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 18 May 2022 02:59:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you ever had a different version of allegro 5 installed? You could be mixing dlls. Don&#39;t cross the streams, Egon!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 23 May 2022 20:45:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve personally had that happen to me with DAllegro being compiled for a slightly different version of Allegro 5 blowing it up.</p><p>But if it &quot;sometimes&quot; crashes. ALWAYS RUN WITH THE DEBUGGER so you CATCH IT when it DOES happen again! GET THAT CALL STACK. You can&#39;t fix something when you don&#39;t even know where it&#39;s crashing.</p><p>Also, isn&#39;t there a way to make Windows/Linux programs that crash, do a &quot;core dump&quot;? It&#39;s a snapshot of the registers and memory when it crashed so a debugger can load it after-the-fact and look at it.</p><p>Linux:</p><p><a href="https://jvns.ca/blog/2018/04/28/debugging-a-segfault-on-linux/">https://jvns.ca/blog/2018/04/28/debugging-a-segfault-on-linux/</a></p><p>Windows:</p><p><a href="https://stackoverflow.com/questions/4672572/how-can-i-configure-windows-to-generate-a-core-dump-from-an-application">https://stackoverflow.com/questions/4672572/how-can-i-configure-windows-to-generate-a-core-dump-from-an-application</a></p><p>Core dumps <b>*should</b>* include the stack. So you can get the stack trace of what functions called what.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 24 May 2022 02:11:00 +0000</pubDate>
	</item>
</rss>
