|
Allegro bitmap is null even when initialized |
Matias Persson
Member #15,093
May 2013
|
Hello folks I've come across this problem where my bitmap will not become initialized. Here is the relevant code; #include "initialize.h" int main() { const float FPS = 60.0; const float frameFPS = 10.0; initialize *init = new initialize(); init->initSystem(FPS, frameFPS); return 0; } Inside initialize.cpp: al_install_keyboard(); al_init_image_addon(); c = new Character("player.png", "Hero", 40, 40, 3); std::cout << c->getName() << ": " << c->getHealth() << " HP." << std::endl; Character.cpp: Character::Character(std::string filePath, std::string n, int var, int var2, int speed) { image = al_load_bitmap(filePath.c_str()); if(image == NULL) { std::cout << filePath.c_str() << " could not be loaded." << std::endl; al_destroy_bitmap(image); } name = n; maxHealth = 10, health = maxHealth; x = var, y = var2, this->speed = speed; }
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Post the full code for the initialize constructor and for initSystem. The loaded png may be null because it was not found. See https://wiki.allegro.cc/index.php?title=Loading_Resources_%28Troubleshooting%29 for more help. 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 |
Matias Persson
Member #15,093
May 2013
|
No, the image is certainly there.. I will post the rest of the code in 2-3 minutes. initialize::initialize() { display = NULL; event_queue = NULL; timer = NULL; frameTimer = NULL; loop = true, redraw = false; }
1int initialize::initSystem(const float FPS, const float frameFPS)
2{
3 if(!al_init())
4 {
5 return -1;
6 }
7
8 display = al_create_display(640, 480);
9 if(!display)
10 {
11 al_destroy_display(display);
12 return -1;
13 }
14
15 event_queue = al_create_event_queue();
16 if(!event_queue)
17 {
18 al_destroy_event_queue(event_queue);
19 al_destroy_display(display);
20 return -1;
21 }
22
23 timer = al_create_timer(1.0 / FPS);
24 if(!timer)
25 {
26 al_destroy_timer(timer);
27 al_destroy_event_queue(event_queue);
28 al_destroy_display(display);
29 return -1;
30 }
31
32 frameTimer = al_create_timer(1.0 / frameFPS);
33 if(!frameTimer)
34 {
35 al_destroy_timer(frameTimer);
36 al_destroy_timer(timer);
37 al_destroy_event_queue(event_queue);
38 al_destroy_display(display);
39 return -1;
40 }
41
42 al_install_keyboard();
43 al_init_image_addon();
44
45 c = new Character("player.png", "Hero", 40, 40, 3);
46 std::cout << c->getName() << ": " << c->getHealth() << " HP." << std::endl;
47
48 al_register_event_source(event_queue, al_get_display_event_source(display));
49 al_register_event_source(event_queue, al_get_timer_event_source(timer));
50 al_register_event_source(event_queue, al_get_keyboard_event_source());
51
52 gameLoop();
53
54 return 0;
55}
|
SiegeLord
Member #7,827
October 2006
|
Matias Persson said: No, the image is certainly there. Stick a al_filename_exists("player.png") somewhere and make sure it returns true. The only other real reason it wouldn't work is if the image addon was compiled without png support (unlikely unless you compiled it yourself) or the png file itself is corrupted. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Matias Persson
Member #15,093
May 2013
|
I am pretty sure that the image file is NOT corrupted, that being said I've both jpg and bmp too which I just saved in paint which usually works.. I'm using pre-compiled Allegro 5.0.10 bins. Edit: I tried al_filename_exists("player.png") and it returns true. Edit edit: The program works now ALL OF A SUDDEN!?!? I haven't changed a thing. |
SiegeLord
Member #7,827
October 2006
|
That's the Allegro way. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Thomas Fjellstrom
Member #476
June 2000
|
Hm, random things happing tend to mean you have a memory corruption issue change a line of code, even adding a printf can "hide" them temporarily. -- |
|