![]() |
|
Crashes because of class |
moon_rabbits
Member #8,469
March 2007
![]() |
I have a class called TerrainClass, and ever since I added it to my program it has caused errors at runtime. Here's the terrain.h and terrain.cpp files: terrain.h Terrain.cpp
And the game class code: game.cpp
Basically, the game.cpp file's functions UpdateState() and Paint() are called every loop, UpdateState() is within a timer to keep the game running at a steady flow. A TerrainClass called terrain is declared in game.h. I think it is something in the constructor for TerrainClass that the error is occuring. When the game is compiled and run it says (in Vista): tank.exe has stopped working. And it has an exit button. What is happening? |
Elverion
Member #6,239
September 2005
![]() |
bmp = create_bitmap(200, 200); I bet this is the problem line. You should be checking it's return value. bmp = create_bitmap(200, 200); if( bmp == NULL ) { allegro_message("bmp is NULL!"); exit(1); }
-- |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
Judging from what you have posted, you are putting your instance of TerrainClass on the stack (Ie "TerrainClass terrain;" instead of "TerrainClass *terrain;" followed by a "terrain = new TerratinClass();" in the init code), which means you will try to create the bitmap before you initiate allegro.
|
moon_rabbits
Member #8,469
March 2007
![]() |
Yeah, it was crashing because Allegro wasn't initialized before the TerrainClass was. I used Jonatan's solution, but now I get these compiler errors and am unsure why: Quote:
- In member function `void GameClass::Paint()': But PaintTerrain has been declared and defined, etc. EDIT: Oops, I'm an idiot. ->! |
|