Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Allegro 5] Game Crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
18 replies to this topic

#1 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 23 October 2012 - 01:29 AM

http://codepad.org/aG4zacD3

My issue is that every time I compile & run it, It waits a couple seconds then crashes. Like, stops responding.

Does anyone have a clue what I'm doing wrong?
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

Sponsor:

#2 Black-Rook   Members   -  Reputation: 1563

Like
-1Likes
Like

Posted 23 October 2012 - 03:57 AM

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:

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

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....
GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

#3 stitchs   Crossbones+   -  Reputation: 1309

Like
2Likes
Like

Posted 23 October 2012 - 01:48 PM

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.

#4 Black-Rook   Members   -  Reputation: 1563

Like
0Likes
Like

Posted 23 October 2012 - 03:06 PM

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!
GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

#5 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 23 October 2012 - 03:13 PM

Which IDE are you using?


I use Code::Blocks for the IDE.
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#6 stitchs   Crossbones+   -  Reputation: 1309

Like
0Likes
Like

Posted 23 October 2012 - 03:53 PM

Have you made a project in CodeBlocks using Allegro 5 before? I just wonder if you have your linkers have been properly set.

#7 Black-Rook   Members   -  Reputation: 1563

Like
1Likes
Like

Posted 23 October 2012 - 04:01 PM

Allegro wiki has all the answers for correctly setting it up.

http://wiki.allegro.cc/index.php?title=Allegro_5
GameDev Journal: http://www.gamedev.n...-rooks-journal/

OpenChess - 1.0 done!

Classic RPG #1 - Task 9 -> January 1st 2013

#8 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 24 October 2012 - 01:13 PM

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.
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#9 Shaquil   Members   -  Reputation: 815

Like
0Likes
Like

Posted 24 October 2012 - 02:58 PM

I'm in class, so I can't exactly check, but off the top of my head:

Add these two lines:

#include <allegro5/image.h>

and somewhere before you create the bitmap

al_init_image_addon();


#10 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 24 October 2012 - 03:31 PM

"allegro5/image.h: No such file or directory".
:/
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#11 Shaquil   Members   -  Reputation: 815

Like
0Likes
Like

Posted 24 October 2012 - 03:49 PM

http://alleg.sourcef....0.7/image.html

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

EDIT:

I'm sorry

#include <allegro5/allegro_image.h>

all better?

Edited by Shaquil, 24 October 2012 - 03:54 PM.


#12 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 24 October 2012 - 04:03 PM

Nope, still crashes at line 59.
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#13 Mike_Stoddart   Members   -  Reputation: 182

Like
0Likes
Like

Posted 24 October 2012 - 04:39 PM

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?

#14 Mike_Stoddart   Members   -  Reputation: 182

Like
-1Likes
Like

Posted 24 October 2012 - 04:42 PM

Change line 41 to:

if(display == NULL) {

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

#15 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 24 October 2012 - 05:03 PM

After I changed line 41 (49 in the code w/Breakpoints&and the new #include by shaquil) to that, the program got compiled & ran just fine, but it still crashed at line 59. (73 in my code)
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#16 Shaquil   Members   -  Reputation: 815

Like
1Likes
Like

Posted 24 October 2012 - 06:01 PM

Change line 41 to:

if(display == NULL) {

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



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.

Attached Thumbnails

  • testofcode.png


#17 King of the Boneheads   Members   -  Reputation: 115

Like
0Likes
Like

Posted 24 October 2012 - 06:41 PM

hmmm...

Well, here's my .cbp (Code Blocks Project file) that contains my .cpp file:

- { http://codepad.org/JCrRLUFQ } -
A Noobie C++ Developer.

I use Code::Blocks with GNU GCC Compiler, and Allegro 5 Libraries.

I'm a W.I.P., please be patient with me!

#18 Shaquil   Members   -  Reputation: 815

Like
0Likes
Like

Posted 24 October 2012 - 07:28 PM

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.

#19 willpowered   Members   -  Reputation: 515

Like
0Likes
Like

Posted 24 October 2012 - 10:02 PM

that code says there's something wrong on line 11. Could that be it?

Highly doubtful, considering that codepad is trying to compile the cbp file as C++ code.

I also second allegro.cc for some help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS