0

I am using liballegro4.2-dev on Ubuntu 14.04 to (hopefully) write a simple game. My code compiles fine using the command g++ Picker.cpp -o out ``allegro-config --libs, but when I run the code I always get the error message Shutting down Allegro due to signal #11 Segmentation fault (core dumped). I suspect this has something to do with the line: masked_blit(face, screen, 0, 0, 0, 0, 64, 64);, but Internet searches turn nothing up and I am out of ideas. The full code is below:

#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();

Thanks for the help!

user266929
  • 11
  • 2
  • Have you tried running the program in a debugger like gdb or ddd? – Mr. Developerdude Jul 03 '15 at 04:28
  • I've only tried debugging with the core dump, which tells me that that line is the problem. Also, it runs if i comment that line out. – user266929 Jul 03 '15 at 04:30
  • Can confirm, compiled with -g and set breakpoint. After step, it returned "Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7aea872 in masked_blit () from /usr/lib/x86_64-linux-gnu/liballeg.so.4.4" – user266929 Jul 03 '15 at 04:34

0 Answers0