|
Hello, font loading keeps crashing in allegro5? |
tonedahconfu
Member #16,358
May 2016
|
ive been trying to figure this out for months now, I read the same topics but i must not be able to understand it. (although i understand it more than struggling with unity and its crazy bad component system) im by no means the most competent C++ programmer, pretty sure im barely considered a beginner. but I try to understand concepts such as running my mainloop logic outside of main (as in, declared headers) not sure thats even a good practice but I've seen other games source code do stuff similar. Anyway sorry about the introduction basically I wanted to make it known that I have a bit of experience getting things to work and this does not. 1#include <iostream>
2#include <cstdio>
3#include <string>
4
5#include <allegro5/allegro.h>
6//
7
8#include <allegro5/allegro_font.h>
9#include <allegro5/allegro_ttf.h>
10
11
12//
13#include <allegro5/allegro_native_dialog.h>
14
15//namespaces
16using namespace std;
17
18//start main
19int main(int argc, char **argv)
20{
21
22 //
23 //printf("Testing allegro...\n");
24 //
25
26 ALLEGRO_DISPLAY *display = NULL;
27
28 if( !al_init() )
29 {
30
31 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize allegro5!", NULL, NULL);
32
33 return -1;
34 }
35
36 al_init_font_addon();
37 al_init_ttf_addon();
38
39
40
41 //
42 display = al_create_display(800, 600);
43
44 if (!display)
45 {
46
47 al_show_native_message_box(NULL, NULL, NULL, "", NULL, NULL);
48
49 return -1;
50 }
51
52
53
54 //
55 //ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
56
57
58
59 ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
60
61 al_append_path_component(path, "resources");
62 al_change_directory(al_path_cstr(path, '/')); // change the working directory
63 //fprintf(path);
64 //return path;
65 cout << path << endl; //returns a hexadecimal memory address? not sure how that helps me, i cant read those.. yet.
66 al_destroy_path(path);
67
68 //
69 //al_change_directory(al_path_cstr(path, '/'));
70 //al_destroy_path(path);
71 ///
72
73 //initialize
74 //
75
76 //
77 ///variable types
78
79 //Fonts
80
81 ALLEGRO_FONT *font24 = al_load_ttf_font("arial.ttf", 24, 0);
82
83 if (!font24)
84 {
85 fprintf(stderr, "Could not load 'arial.ttf'.\n");
86 return -1;
87 }
88
89 //
90
91 //
92 al_clear_to_color(al_map_rgb(0, 0, 0));
93 //
94 //draw to screen
95 //al_draw_text(font24, al_map_rgb(255, 0, 255), 50, 50, 0, "Test text.");
96
97 al_draw_text(font24, al_map_rgb(200,0,200), 50.0, 50.0, 0, "Hello World");
98
99 //printf("Failed to load font!\n");
100
101
102 //
103 al_flip_display();
104 al_rest(10.0);
105
106
107
108 al_destroy_font(font24);
109
110 //
111 al_destroy_display(display);
112 //
113
114 return 0;
115
116}
pardon my code it is a mess, but ive been on this same problem for months now, and its been a headache, so its be rewritten hastily quite a few times. i have other code which loads images just fine, so im not even sure what the problem is at all. basically the code will either locate the font and then crash with an exit error of: |
Peter Hull
Member #1,136
March 2001
|
I tried this code and it worked first time for me (allegro 5.2, MSVC). Are you sure the arial.ttf is OK and not corrupted in some way? (I used a different font that I had lying around) On your ALLEGRO_PATH stuff, you can use ALLEGRO_NATIVE_PATH_SEP instead of hardcoding '/' and if you want to display the path on cout, just use al_path_cstr again, i.e. cout << al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP) << endl;
You're right, just displaying a hex number is not helpful! [edit] -1073741819 is 0xC000 0005 in hex - that's an HRESULT with STATUS_SEVERITY_ERROR..FACILITY_NULL...STATUS_ACCESS_VIOLATION
|
tonedahconfu
Member #16,358
May 2016
|
Thank you for your response, however after trying to figure it out I've decided that in the interest of keeping my sanity it's best I let it go. Thanks again, really wanted to get into Allegro5 but I don't see it happening any time soon. I wonder why this library has issues accessing fonts when SFML was doing fine? I mean it accesses images fine, and it just doesnt make any sense. I wish I was a stronger man, but this is causing me horrible head pain. Thank you again. |
|