Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » TTF Loading Failing

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
TTF Loading Failing
mumu1000
Member #16,842
April 2018

Hello Everybody !
I'm new to Allegro Programming (and programming in general :P ) and i get an error i don't even know the meaning of :(

I Just want to make a "Hello World" test program, everything works fine, until i try to load a ttf font (it worked with the builtin font).

#SelectExpand
1 2#include <iostream> 3#include <string> 4#include "allegro.h" 5#include "allegro_color.h" 6#include "allegro_font.h" 7#include "allegro_ttf.h" 8 9int main(int argc, char **argv) 10{ 11 bool allegroIsWorking = al_init(); 12 bool alfontIsWorking = al_init_font_addon(); 13 bool alTTFIsWorking = al_init_ttf_addon(); 14 if(allegroIsWorking && alfontIsWorking && alTTFIsWorking) 15 { 16 cout << "It Works\n"; 17 } 18 ALLEGRO_DISPLAY * Ecran = al_create_display(1000,500); 19 ALLEGRO_FONT * font = al_load_ttf_font("Roboto-Bold.ttf",70,0); 20 al_clear_to_color(al_map_rgb(0,0,0)); 21 al_draw_text(font,al_map_rgb(255,255,255), 2,2,0,"Hello world"); 22 al_flip_display(); 23 24 25 return 0; 26}

There are no compilation errors.
The TTF file "Roboto-Bold.ttf" is in the program folder.
When i use "al_create_builtin_font" instead of "al_load_ttf_font" it works perfectly.
At runtime, the debug console displays "It Works" and creates the display before crashing.
The crash message displayed in the console is:

Assertion failed!

Program: C:\Users\PathToMyProgam\program.exe
File: C:/dev/allegro_winpkg/universal/allegro/addons/font/text.c, Line 79

Expression: font

Please, can someone tell me what messes everything up ? :'( :'( :'(
2 hours i've been trying to solve this without success :-X

Thank you very much !!!

Edit:
After "al_laod_ttf_font" font pointer is null, so it means it doesn't find the font, but i double checked and the ttf file is in the exe folder... :-/:-/
Any ideas ?

Edit Edit:
I found the problem, but its still really really weird:

I use code::blocks, and when i run the program from code::blocks, it crashes.
But, when i run the program directly from the .exe file in the bin/debug folder of my project... IT WORKS !

I actually have no idea what caused this bug tho, and i would be interested if someone had an idea :D

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

mumu1000
Member #16,842
April 2018

Thank you very much !
Its weird the working directory isnt the good one by default...

Have a good day ^^

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The working directory is where ever you ran the program from. There's a setting in CB that lets you change the executable's current working directory.

{"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"}611416

However, that doesn'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.

ALLEGRO_PATH* p = al_get_standard_path(ALLEGRO_EXENAME_PATH);
al_change_directory(al_path_cstr(p) , ALLEGRO_NATIVE_PATH_SEP);
al_destroy_path(p);
p = 0;

Go to: