[A5] Allegro assertion failure with TTF font addon.

I threw together a simple little program to test out loading TTF fonts and it doesn't seem to load in the font. I copied the TTF from the examples folder so it's in the same directory as the program running.

Anyhow, when I run this it gets some Assertion failure.

"Assertion failed: vec->_itemsize > 0, file d:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\src\misc\vector.c, line 170"

This happens on the line #9 below.

I installed the prebuilt libraries (for 4.5.0) with CodeBlocks + MinGW (gcc 4.5.2).

It's not that important, I'm just playing around trying to get used to this version of the library.

1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_ttf.h> 4 5int main(int argc, char *argv[]) 6{ 7 al_init(); 8 al_install_keyboard(); 9 al_init_ttf_addon(); 10 11 ALLEGRO_DISPLAY *display = al_create_display(800, 600); 12 if (!display) 13 { 14 printf("Unable to set display."); 15 al_rest(3); 16 exit(1); 17 } 18 ALLEGRO_KEYBOARD_STATE keyboard; 19 ALLEGRO_FONT *font; 20 21 font = al_load_ttf_font("DejaVuSans.ttf", 20, 0); 22 if(!font) 23 { 24 printf("Error loading font."); 25 al_rest(3); 26 exit(1); 27 } 28 29 while(!al_key_down(&keyboard, ALLEGRO_KEY_ESCAPE)) 30 { 31 al_draw_text(font, al_map_rgb(255, 255, 0), 20.0, 20.0, 0, "Hello world!"); 32 33 al_get_keyboard_state(&keyboard); 34 al_flip_display(); 35 } 36 37 al_shutdown_ttf_addon(); 38 al_uninstall_keyboard(); 39 al_uninstall_system(); 40 41 return 0; 42}

Peter Wang

You need to call al_init_font_addon() before al_init_ttf_addon().


I actually used to have that in my code, I removed it not thinking I needed it. But the same problem exists with or without it.

Adding it back in and recompiling comes up with the same thing.

1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_font.h> 4#include <allegro5/allegro_ttf.h> 5 6int main(int argc, char *argv[]) 7{ 8 al_init(); 9 al_install_keyboard(); 10 al_init_font_addon(); 11 al_init_ttf_addon(); 12 13 ALLEGRO_DISPLAY *display = al_create_display(800, 600); 14 if (!display) 15 { 16 printf("Unable to set display."); 17 al_rest(3); 18 exit(1); 19 } 20 ALLEGRO_KEYBOARD_STATE keyboard; 21 ALLEGRO_FONT *font; 22 23 font = al_load_ttf_font("DejaVuSans.ttf", 20, 0); 24 if(!font) 25 { 26 printf("Error loading font."); 27 al_rest(3); 28 exit(1); 29 } 30 31 while(!al_key_down(&keyboard, ALLEGRO_KEY_ESCAPE)) 32 { 33 al_draw_text(font, al_map_rgb(255, 255, 0), 20.0, 20.0, 0, "Hello world!"); 34 35 al_get_keyboard_state(&keyboard); 36 al_flip_display(); 37 } 38 39 al_shutdown_ttf_addon(); 40 al_shutdown_font_addon(); 41 al_uninstall_keyboard(); 42 al_uninstall_system(); 43 44 return 0; 45}

Edit: I am beginning to think it has something to do with the prepackaged binaries for Allegro 5 (mingw 4.5.0). I downloaded them as I could only compile the release version of the Allegro 5 dlls and can't for the life of me get it to compile debug and other versions. BUT, after I installed those binaries, I now can't even successfully recompile Allegro release, so I deleted CodeBlocks/MinGW etc... and am doing a fresh install, I'll recompile Allegro myself with updated GCC etc... and let you know how that goes. It seems as though I'll be forced to figure out how to compile allegro debug versions... >:(

Thomas Fjellstrom

I think the ttf and/or font addon might want the primitive addon as well.


I think the ttf and/or font addon might want the primitive addon as well.

They don't.

The latest code actually works fine for me (except for a bizzare crash when calling al_shutdown_ttf_addon()). I've no clue what might be wrong.


Great, I just tried recompiling from a fresh install of EVERYTHING, my IDE, MinGW, you name it... Allegro 4 compiled up just fine, debug/release versions. Allegro 5... more errors... I think I am just about done with Allegro 5, I may stick with 4... I have spent many hours today trying to figure this shit out and am getting tired of it.

pandoc: \s2pg.: openFile: does not exist (No such file or directory)
C:\Users\Neil\Develop\allegro\docs\scripts\make_doc.c:196: system call failed: p
andoc \s2pg.  --include-before-body inc.a.html --include-after-body inc.timestam
p.html --include-after-body inc.z.html --css pandoc.css --include-in-header C:/U
sers/Neil/Develop/allegro/docs/src/custom_header.html --standalone --toc  --to h
tml --output \s2pg.1
mingw32-make[2]: *** [docs/html/refman/getting_started.html] Error 1
mingw32-make[1]: *** [docs/CMakeFiles/html.dir/all] Error 2
mingw32-make: *** [all] Error 2

What next???


That's just the documentation generation. Either do -DWANT_DOCS=off on the command line or find the WANT_DOCS variable in the gui.

Matthew Leverton

I would use the precompiled Allegro 5 libraries.


I tried the precompiled versions and that's where I had problems. SO I done a fresh install so I could compile 'em myself. Last time I installed MinGW with CodeBlocks it compiled fine. This time around I installed CodeBlocks without MinGW because I want it seperare, I installed MinGW and MinGW-get and updated it so gcc is up to 4.5.2. Something missing I presume, gawd only knows. This version of allegro, while looking great, is very annoying to compile. Tracking down the dependencies alone is a royal pain let alone navigating the labyrinth that is cmake.

I'll keep searching... I feel like deleting allegro 5, but I just can't give up once I get fixated on it... but I am close... >:(

I'm assuming there's something missing that is used to generate the docs in the stand alone MinGW I installed....

Edit: -DWANT_DOCS=off seemed to work nicely. It still bugs me what is missing though, but that's good enough for now. Still waiting on the debug compile to finish then I'll try recompiling this program...

Update: Okay, it worked this time. So there's something wrong with using the prebuilt binaries with MinGW. I downloaded the prebuilt binaries for MinGW 4.5.0 and that is where I had problems. After a fresh install of MinGW 4.5.2 and all the dependencies I could track down, and compiling it myself, there is no problem. I still don't know what I am missing for the docs to compile, I downloaded and installed Pandoc again. <shrug>

Thomas Fjellstrom

You need to make sure you're downloading the right binaries. There's 4 separate mingw binaries for Allegro 5. Each one is for a separate gcc version.


Yup. And I downloaded 4.5.0, I have 4.5.2, all I can guess is that I needed MinGW for 4.5.0. Which means I need to compile it myself, which I am getting better at. ;) I still don't know why the docs won't compile, not important, but it bugs me.

I actually prefer to compile it myself, I always have since I started with Allegro 1 or 2. One good thing from all this, I've almost memorized what I need to type for cmake now. ;)

Oh, one more on topic question, is there a way to display TTF fonts with anti-aliasing on? I noticed they were aliased when displayed with the above program.

Edit: okay, helps if I clear the background to black first. ;)

Thread #606685. Printed from Allegro.cc