Allegro c++ segmentation fault!!!

so here is the code for the main text document (main.cpp) :

#include <allegro.h>
#include "map.cpp"
using namespace std;

int closed = 0;
int ex,height;
int rate = 1;
int jump = 0;

int main() {

allegro_init();
install_keyboard();
set_gfx_mode (GFX_AUTODETECT_WINDOWED,1200,700,0,0);

BITMAP *player = load_bitmap ("player.bmp",NULL);

height = 0;
mapex = 0;
ex = 0;

while (closed == 0) {

if (key[KEY_ESC]) {closed = 1;}
if (key[KEY_W]) {jump = 1;}
if (key[KEY_A]) {ex = ex + rate;}
if (key[KEY_D]) {ex = ex - rate;}
if (ex <= 0) {ex = ex + rate;}
if (ex >= 1200) {ex = ex - rate;}
mapex = 0 - ex*2;

add_map();
draw_sprite (map,player,ex,height);
clear_to_color(map,makecol(0,0,0));
}
destroy_bitmap(map);
destroy_bitmap(player);
return 0;
}

ok, so u probaly noticed that there is another source file called map.cpp,
and here it is (the one with the function add_map(); :

BITMAP *map = load_bitmap ("map.bmp",NULL);
int mapex;

void add_map() {

draw_sprite (screen,map,mapex,0);

}

ok so im compiling with this command in the linux terminal:

g++ -W -Wall -s -O2 -pipe test1.cpp -o test1.exe `allegro-config --libs`

ok so when i run, it says segmentation fault(core dumped)

HELP MEEEEEE!!!
Instead of trying to link the sources files directly, use a header file.
1
2
3
4
5
6
#ifndef MAP_H
//Directives to avoid accidental redefining when header files is used in multiple source files
#define MAP_H
//Header file called "map.h" and filled with prototypes
void add_map();
#endif 
Last edited on
Topic archived. No new replies allowed.