- Online Community Forums » Programming Questions » Looking for addons in wrong directory

This thread is locked; no one can reply to it. rss feed Print
Looking for addons in wrong directory
Member #15,510
February 2014

I am currently following a tutorial for Allegro 5 and when trying to use al_draw_text, I get a seg fault. After using gdb, I found that it is looking in my downloads directory for the text addon. Any idea why this would be?

I am on Linux Mint 16, using g++ 4.8.1 and Allegro 5.0.11.

GDB output:

Program received signal SIGSEGV, Segmentation fault.
al_draw_ustr (font=font@entry=0x0, color=..., x=x@entry=50, y=50, flags=flags@entry=0, ustr=0x7fffffffdf80)
    at /home/me/Downloads/allegro/addons/font/text.c:93
93  /home/me/Downloads/allegro/addons/font/text.c: No such file or directory.

GDB backtrace:

#0  al_draw_ustr (font=font@entry=0x0, color=..., x=x@entry=50, y=50, flags=flags@entry=0, ustr=0x7fffffffdf80)
    at /home/me/Downloads/allegro/addons/font/text.c:93
#1  0x00007ffff76f5183 in al_draw_text (font=0x0, color=..., x=50, y=<optimized out>, flags=0, text=<optimized out>)
    at /home/me/Downloads/allegro/addons/font/text.c:106
#2  0x0000000000400c41 in main () at main.cpp:29

My tutorial file:

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4#include <allegro5/allegro_native_dialog.h> 5 6int main(void) { 7 ALLEGRO_DISPLAY *display = NULL; 8 9 if (!al_init()) { 10 al_show_native_message_box(NULL, NULL, NULL, 11 "failed to initialize allegro!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 12 return -1; 13 } 14 15 display = al_create_display(640, 480); 16 17 if (!display) { 18 al_show_native_message_box(NULL, NULL, NULL, 19 "failed to initialize display!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 20 return -1; 21 } 22 23 al_init_font_addon(); 24 al_init_ttf_addon(); 25 26 ALLEGRO_FONT *font24 = al_load_font("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-Mono-R.ttf", 24, 0); 27 28 al_clear_to_color(al_map_rgb(0, 0, 0)); 29 al_draw_text(font24, al_map_rgb(255, 0, 255), 50, 50, 0, "You like my font?"); 30 al_flip_display(); 31 al_rest(3.0); 32 al_destroy_display(display); 33 34 return 0; 35}


1CXX=g++ 2CFLAGS= 3LDFLAGS=-L/usr/lib -lallegro -lallegro_dialog -lallegro_font -lallegro_ttf 4INCLUDE=-I. -I/usr/include/allegro5 5 6OBJS=main.cpp 7OUT=main 8 9all: main 10 11main: $(OBJS); $(CXX) $(OBJS) -o $(OUT) $(INCLUDE) $(CFLAGS) $(LDFLAGS) 12 13debug: $(OBJS); $(CXX) -O0 -g $(OBJS) -o $(OUT) $(INCLUDE) $(CFLAGS) $(LDFLAGS) 14 15clean: ; rm -rf *.o main

Member #14,001
February 2012

Check if the font is actually loaded by verifing the retunr code of al_load_font

From what you posted it seems that GDB is looking for the source file in your downloads directory (which makes sense after all, I guess), but the SegFault seems due to invalid font pointer...which in turn may be caused by a failed load operation.

Someone will point out that you should always check return values... :P

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Member #15,510
February 2014

Thanks! I thought I had checked it but obviously I didn't, works fine now!

Thomas Fjellstrom
Member #476
June 2000

That no such file or directory message is just gdb looking for the source so it can show the source at the line it crashed at. It's not a fatal error or related to the crash at all.

Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" --

Edgar Reynaldo
Member #8,592
May 2007

It is looking for the source code in the place it was compiled, which may have been on a different machine.

Go to: