|
Font loading crashing with Allegro 5.2 |
240-185
Member #15,795
November 2014
|
Hi, I'm desperately trying to load a .TTF font in Allegro, but every font I tried to load led to a crash! I even tried to a load a font taken from a previous project made with a previous version of Allegro 5, with no luck. I don't understand what's going on. Can you please help me? Here's the code: 1int main(int argc, char **argv)
2{
3 ALLEGRO_BITMAP *bouncer = NULL;
4ALLEGRO_FONT *freesans = NULL;
5
6 float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
7 float bouncer_y = 4;
8 float bouncer_dx = -4.0, bouncer_dy = 4.0;
9 bool redraw = true;
10 short quit=0;
11
12 if(!al_init()) {
13 fprintf(stderr, "failed to initialize allegro!\n");
14 exit(-1);
15 }
16
17 al_init_image_addon();
18 al_init_primitives_addon();
19 al_init_font_addon();
20 al_init_ttf_addon();
21 al_init_acodec_addon();
22 al_install_audio();
23 al_install_keyboard();
24 al_install_mouse();
25
26 al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);
27 al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, 1, ALLEGRO_REQUIRE);
28 al_set_new_display_option(ALLEGRO_RENDER_METHOD, 0, ALLEGRO_REQUIRE);
29 al_set_new_display_flags(ALLEGRO_FULLSCREEN);
30
31 voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
32 mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
33
34 al_set_new_bitmap_flags(ALLEGRO_NO_PREMULTIPLIED_ALPHA);
35 al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
36
37 al_attach_mixer_to_voice(mixer, voice);
38
39 srand(time(NULL));
40
41 timer = al_create_timer(1.0 / FPS);
42
43 display = al_create_display(SCREEN_W, SCREEN_H);
44
45 freesans = al_load_ttf_font("Pokemon_GB.ttf", 12, 0); // <- it crashes right there
46
47 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE);
48
49 al_set_target_bitmap(bouncer);
50 al_clear_to_color(al_map_rgb(random(255), random(255), random(255)));
51 al_set_target_bitmap(al_get_backbuffer(display));
52
53 event_queue = al_create_event_queue();
54 if(!event_queue) {
55 fprintf(stderr, "failed to create event_queue!\n");
56 al_destroy_bitmap(bouncer);
57 al_destroy_display(display);
58 al_destroy_timer(timer);
59 return -1;
60 }
61
62 al_register_event_source(event_queue, al_get_display_event_source(display));
63 al_register_event_source(event_queue, al_get_timer_event_source(timer));
64 al_clear_to_color(al_map_rgb(0,0,0));
65 al_flip_display();
66 al_start_timer(timer);
67
68
69 while(!quit)
70 {
71 ALLEGRO_EVENT ev;
72 al_wait_for_event(event_queue, &ev);
73
74 if(ev.type == ALLEGRO_EVENT_TIMER) {
75 if(bouncer_x < 0 || bouncer_x > SCREEN_W - BOUNCER_SIZE) {
76 bouncer_dx = -bouncer_dx;
77 al_set_sample_instance_pan(mkayyy.instance, LEFT);
78
79 }
80
81 if(bouncer_y < 0 || bouncer_y > SCREEN_H - BOUNCER_SIZE) {
82 bouncer_dy = -bouncer_dy;
83 al_set_sample_instance_pan(mkayyy.instance, RIGHT);
84
85 }
86
87 bouncer_x += bouncer_dx;
88 bouncer_y += bouncer_dy;
89
90 redraw = true;
91 }
92 else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
93 break;
94 }
95
96 if(redraw && al_is_event_queue_empty(event_queue)) {
97 redraw = false;
98
99 al_clear_to_color(al_map_rgb(0,0,0));
100
101 al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);
102
103 al_flip_display();
104 }
105
106
107 al_get_keyboard_state(&kbdstate);
108 if (al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE))
109 {
110 quit=1;
111 }
112 }
113
114 al_destroy_bitmap(bouncer);
115 al_destroy_timer(timer);
116 al_destroy_display(display);
117 al_destroy_event_queue(event_queue);
118
119 return 0;
120}
|
SiegeLord
Member #7,827
October 2006
|
Can you link a copy of your font so we can try it on our machines? Also, does your display create? Check to see if it's NULL. I tried the font from http://www.fonts2u.com/pokemon-gb.font and it worked fine, but I don't know if its the same font as you have. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
240-185
Member #15,795
November 2014
|
The display is created correctly, as the program crashes after entering this screen mode. Just in case: on which OS did you try my piece of code? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Have you checked your current working directory? DevCPP may be running your program from a different directory than you expect. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
240-185
Member #15,795
November 2014
|
Every other thing I load into memory loads fine as I'm always working with relative paths. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I successfully loaded and displayed each of your three fonts on my computer running Windows 10. I used my MinGW 5.3.0-2 binaries of Allegro 5.2.1.1 to compile them. First, check your return values. Second, make sure your binaries are compatible with your compiler. Third, make sure you're using the correct dlls if linking dynamically. Fourth, link to the debug version of allegro and see if any ASSERTS fail or if allegro.log has any clues as to why it is failing. {"name":"610556","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/f\/df03973c42d5cc2e66d93ff87db4d196.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/f\/df03973c42d5cc2e66d93ff87db4d196"} My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|