我在Ubuntu 14.04上使用liballegro4.2-dev来(希望)编写一个简单的游戏。我的代码使用命令g++ Picker.cpp -o out ``allegro-config --libs
编译得很好,但是当我运行代码时,我总是收到错误消息Shutting down Allegro due to signal #11 Segmentation fault (core dumped)
。我怀疑这与该行有关:masked_blit(face, screen, 0, 0, 0, 0, 64, 64);
,但互联网搜索没有任何结果,我没有想法。完整代码如下:
#include <allegro.h>
void setUpAllegro()
{
//INIT
allegro_init();
install_keyboard();
install_timer();
install_mouse();
install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, 0 );
set_color_depth( 16 );
bool fullscreen = false;
if (fullscreen == true)
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
else
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
//END INIT
}
class Player
{
public:
int x;
int y;
void Move(int dir)
{
switch(dir)
{
case 1:
y += 5;
break;
case 2:
y -= 5;
break;
case 3:
x += 5;
break;
case 4:
x -= 5;
break;
default:
//exit(1);
break;
}
}
};
int main()
{
setUpAllegro();
Player player;
bool done = false;
BITMAP *buffer = create_bitmap( 640, 480 );
BITMAP *face;
face = load_bitmap("/home/alexander/Desktop/Pooper Picker/fake.BMP",NULL);
while (!done)
{
if( key[KEY_ESC] )
done = true;
if( key[KEY_UP])
player.Move(1);
else if( key[KEY_DOWN] )
player.Move(2);
if ( key[KEY_LEFT] )
player.Move(3);
else if( key[KEY_RIGHT] )
player.Move(4);
masked_blit(face, screen, 0, 0, 0, 0, 64, 64);
blit( buffer, screen, 0, 0, 5, 5, 640, 480 );
release_screen();
clear_bitmap( buffer );
}
//free memory
destroy_bitmap( buffer );
return 0;
}
END_OF_MAIN();
感谢您的帮助!