Sign in to follow this  

[Allegro 5] Game Crash

This topic is 1911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Your error code states "Line 29: error: allegro5/allegro.h: No such file or directory", are you sure that you're using the right path for allegro.h ?

I noticed errors in your code:

[CODE]if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}[/CODE]

All you're doing is checking if al_init() returns false... Yet you never called al_init().

You need to call the following right before the check to see if they return false.

al_init();
al_install_keyboard();

ect....

Share this post


Link to post
Share on other sites
I have to disagree with the error you pointed out. I use conditional checks like that in my code and I have never had an issue. With his code it becomes somewhat condensed by calling the method and checking it's false. If it is false it exits the program, if it's true it continues on.

al_init() is called in this usage, it just saves an additional line by calling it in one if statement, than calling it, and then checking 3-7 lines later.

In response to the original question, it sounds most likely what Black-Rook suggested, that you may not have linked the libraries correctly to your project. Which IDE are you using?

Regards,

Stitchs.

Share this post


Link to post
Share on other sites
Oops, was 3am while writing! Guess I wasn't fully thinking there. Yes he is right, it goes through the function on the check while performing the inialization, then returns true or false.

Sorry about that!

Share this post


Link to post
Share on other sites
First things first, yes, in fact this .cpp file is IN a Code::Blocks project file, linked to all allegro things necessary. I have followed that Allegro 5 tutorial, and it's not the projects fault (I think).

So I set some breakpoints (well, I printed at various points in code)

And tracked it down to which line it crashes on, and:

http://codepad.org/kOFCWkA5

It seems to crash at line 59. "al_set_target_bitmap(al_get_backbuffer(display));"

I really need someone who's advanced to help me out, because the answer is not exactly obvious as to why it crashed.

Share this post


Link to post
Share on other sites
I'm in class, so I can't exactly check, but off the top of my head:

Add these two lines:

[CODE]#include <allegro5/image.h>[/CODE]

and somewhere before you create the bitmap

[CODE]al_init_image_addon();[/CODE]

Share this post


Link to post
Share on other sites
[url="http://alleg.sourceforge.net/a5docs/5.0.7/image.html"]http://alleg.sourcef....0.7/image.html[/url]

it exists. Maybe you're not linking right. Hmm

EDIT:

I'm sorry

#include <allegro5/allegro_image.h>

all better? Edited by Shaquil

Share this post


Link to post
Share on other sites
Assign the return value of al_get_backbuffer and make sure it's valid. Probably it's returning null? I don't know allegro but did you initialize it with the option of using the backbuffer?

Share this post


Link to post
Share on other sites
Change line 41 to:

if(display == NULL) {

The manual says that al_create_display returns NULL, so don't assume it's Boolean value.

Share this post


Link to post
Share on other sites
[quote name='Mike_Stoddart' timestamp='1351118565' post='4993582']
Change line 41 to:

if(display == NULL) {

The manual says that al_create_display returns NULL, so don't assume it's Boolean value.
[/quote]


That's a waste of time. if(!display) and if(display == NULL) are the same exact thing.

Also, remove my suggestion of the image addon stuff. I was wrong. I've run your code in Visual Studio 2012 Professional. It worked. I've attached a screenshot in dual-screen mode. I have no idea how to make allegro work with codeblocks, so I can't help you with figuring out what possible linkage problems might be occuring.

Share this post


Link to post
Share on other sites
that code says there's something wrong on line 11. Could that be it? I hope you figure this out. I'm honestly perplexed. It seems like something going on under the API itself. Or maybe you've downloaded a version of allegro that isn't compatible with whatever compiler code::blocks uses. Try allegro.cc, the users on that forum are active and knowledgable. It seems very few people here honestly use allegro.

Share this post


Link to post
Share on other sites
[quote name='Shaquil' timestamp='1351128486' post='4993618']
that code says there's something wrong on line 11. Could that be it?
[/quote]
Highly doubtful, considering that codepad is trying to compile the cbp file as C++ code.

I also second allegro.cc for some help.

Share this post


Link to post
Share on other sites
Sign in to follow this