Why the exception?

Hi, just for info in this project I am playing around with Allegro(library for some easy game programming)
First let me paste the needed code:

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "system.h" // all the needed headers and definitions are included here (level.h,...)

int main()
{
	System system;

	Level level;
	Item item;
	Character player;
	
	system.Setup();

	BITMAP *buffer = create_bitmap(WIDTH, HEIGHT);

	int iCnt = 0;

	/* Game loop */
	while (!key[KEY_ESC]) 
	{
		iCnt++;
		/*player.GetInput();
		player.Update();*/
						
		level.Draw(buffer);   // this is where the exception happens
		//item.Draw(buffer);
		//player.Draw(buffer);
		
		//textprintf_ex(buffer, font, 200, 300, makecol(255, 0, 255), -1, "i = %d", iCnt);
		blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);
		clear_bitmap(buffer);
	}
	
	destroy_bitmap(buffer);

    return 0;
}   
END_OF_MAIN(); 


Level.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Level::Level(void)
{
	levelBMP = load_bitmap("image.bmp", NULL);
}


Level::~Level(void)
{
}

void Level::Draw(BITMAP *tmpBMP)
{
	masked_blit(levelBMP, tmpBMP, 0, 0, 0, 0, WIDTH, HEIGHT);
}


Level.h
1
2
3
4
5
6
7
8
9
10
11
#pragma once
class Level
{

public:
	BITMAP *levelBMP;
	Level(void);
	~Level(void);
	void Draw(BITMAP *);
};


There are two more classes implemented exactly the same way, the Item and Character classes.
Ok, so this was the code, now basically I don't understand what the problem is, I've got a hunch that it's got something to do with the BITMAP point being passed to the Draw() function.

I don't know what else to add, so if I asked it weird or left out any important bit, let me know, otherwise thanks for all/any help.

Last edited on
Okay as far as I have figured out by now, it seems as if there is a problem with the levelBMP, since I can't even get it's parameters, without an exception. I have some suspicions on the levelBMP = load_bitmap("image.bmp", NULL);

Still lost though.
G-damn it :P

I found it, the problem was that I put
system.Setup();
after I created the objects, but the constructors had in them Allegro functions, and Allegro has to be intilized before anything can be used, and therefor the load_bitmap function failed.

Nice one :)

Have a nice one.
Topic archived. No new replies allowed.