Search code examples
cosx-elcapitanallegroallegro5

Allegro displaying weird corrupt visuals


I have been trying to use Allegro but finding that sometimes when I call al_flip_display instead of the expected result, I get a display of corrupt messy nonsense, sometimes white noise, sometimes sections of other portions of my screen. To me that seems like the buffer is sharing memory with something else but I have no real idea what could be causing it.

I've tried to write a minimal program that demonstrates this problem. What is meant to happen is that every time a key is pressed another section of a diagonal line is drawn on the display. What actually happens is when I press a key I get a corrupt visual mess, and then when I press a key again I get what I am expecting, pressing it again goes back to the mess, pressing it again gives what I want. I.e. it seems to only affect one of the buffers.

There's a couple of screenshots at the bottom of what kind of thing happens when a key is pressed.

Any ideas?

The code:

#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>

int main(void)
{
    ALLEGRO_DISPLAY *display = NULL;
    int i = 0;

    if (!al_init()) return 1;
    if (!al_init_primitives_addon()) return 1;

    display = al_create_display(640, 480);

    if (!display) return 1;

    for (i=0; i<10; i++) {
        al_draw_line(0+i*20, 0+i*20, 50+i*20, 50+i*20, al_map_rgb(255,255,255), 1);
        al_flip_display(); // this is where the error happens
        getchar(); // wait for next keypress
    }

    al_destroy_display(display);

    return 0;
}

Compiled and executed with the following on OS X El Capitan with Allegro 5.0:

clang `pkg-config allegro-5.0 allegro_main-5.0 allegro_primitives-5.0 --cflags --libs` test1.c -o test1.o && ./test1.o

Note that this doesn't seem to happen for me when I run it with MinGW on Windows. Only on my OS X laptop does it happen. Haven't tried it on anything else. Could it be a bug with Allegro in OS X?

An example of what happens Another example


Solution

  • As a note to anyone with this problem. The issue was a bug in Allegro in OS X El Capitan, and the solution was to use the development version of Allegro where the bug is fixed.

    As this was a few months ago, those changes may be in the production version now.