11

I'm starting at Allegro 5, but soon I got stuck in the second hello-world-like program I'm coding. After some debugging, I concluded that the program crashes when it calls the function al_clear_to_color(ALLEGRO_COLOR). I've tried linking allegro statically and dynamically, but the problem still remains. I'm completely lost.

Here is the code:

#include <cstdio>
#include <allegro5/allegro.h>

int main() {
    ALLEGRO_DISPLAY         *display;
    ALLEGRO_KEYBOARD_STATE  kbState;

    if(!al_init())
        return 0;

    if(!al_install_keyboard())
        return 0;

    display = al_create_display(800, 600);
    if(!display)
        return 0;

    do {
        al_get_keyboard_state(&kbState);

        al_clear_to_color(al_map_rgb(255, 255, 255));

        al_flip_display();

        al_rest(0.5);
    } while(!al_key_down(&kbState, ALLEGRO_KEY_ESCAPE));

    al_destroy_display(display);

    return 0;
}

edit:

Substituting the line

al_clear_to_color(al_map_rgb(255, 255, 255));

for the line

al_clear_to_color(tempClearColor);

declaring

ALLEGRO_COLOR tempClearColor = al_map_rgb(255, 255, 255);

before the loop starts, it does work, but crashes when the function

al_destroy_display(display);

is called.

The debugger returns the messages:

Error while reading shared library symbols for C:\Program Files (x86)\CodeBlocks\MinGW\bin\libstdc++-6.dll:
Program received signal SIGSEGV, Segmentation fault.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Bruno Garcia
  • 111
  • 6
  • 1
    Compile against the debug version of Allegro and check out the logs. Nothing we can do from here... – Matthew Feb 16 '13 at 05:25
  • 2
    I can't see anything wrong in your code. Have you tried using other drawing functions besides `al_clear_to_color()` to confirm that is the specific function that is causing the error? Have you tried changing the RGB values to see if that changes anything? Maybe try adding a line before your do loop that just creates a new ALLEGRO_COLOR object with al_map_rgb() to see if that is the function that is actually causing the problems. – Alex Feb 16 '13 at 07:31
  • 2
    Did you build Allegro yourself? If not, does `gcc -v` match *exactly* the Allegro version you downloaded? – Matthew Feb 16 '13 at 15:52
  • It "almost" matches, the Allegro release i've downloaded is built for GCC 4.7.0 and the GCC i'm using is 4.7.1. Even though i'm awful at compiling libraries, i'll try to compile the Allegro 5 by myself. – Bruno Garcia Feb 16 '13 at 20:42
  • This thread: https://www.allegro.cc/forums/thread/610189 suggests it is likely to be incompatible compilation of your code versus the library, as Matthew's question suggests. – Ron Burk Feb 17 '13 at 07:52

0 Answers0