DerelictOrg / DerelictAllegro5

A dynamic binding to the Allegro 5 library for the D Programming Language.
3 stars 1 forks source link

Error with clearing screen #7

Open joelcnz opened 7 years ago

joelcnz commented 7 years ago
import derelict.allegro5;

import std.stdio: writeln;

ALLEGRO_DISPLAY* DISPLAY;

int main() {
    DerelictAllegro5.load();

    DerelictAllegro5.run( {
        if (! al_init()) {
            writeln("failed to initialize allegro!");
            return -1;
        }

        DISPLAY = al_create_display( 640, 480 );
        assert(DISPLAY, "failed to create display");
        scope(exit) al_destroy_display( DISPLAY );

        al_clear_to_color(al_map_rgb(255,180,0)); //#error return value -11
        al_flip_display();

        al_rest(2);

        return 0;
    } );

    return 0;
}
mdparker commented 7 years ago

Joel, if you have bugs with DerelictAllegro5, this is definitely the place to post them. But this is not an Allegro support forum. I don't use Allegro that much myself and for me to help you would require me to dig into the Allegro docs and debug your programs for you. I don't have time for that. Please take issues like this to the Allegro forums at allegro.cc if you can't solve them yourself. If you later determine a problem is with the binding, then by all means report it here.

mdparker commented 7 years ago

Alright, I need you to clarify something. When you said "error return value", it sounded like you were talking about the return value of a function. But are you actually talking about a message you're getting from the system?

joelcnz commented 7 years ago

Yes, it displays "Program exited with code -11" in the terminal, when I run the program.

joelcnz commented 7 years ago

Also, I posted it on allegro.cc and some one said that the code worked on DAllegro, using Linux.

mdparker commented 7 years ago

I've tested your code on my MacBook and it crashes for me, too. Running in the debugger shows a segmentation fault. Looks like it's a thread-related issue. Marking DISPLAY as __gshared or moving the declaration inside the function literal makes the crash go away.

I recommend using __gshared on any of your globals for now, just as a temporary workaround until I can figure out how to solve this.

joelcnz commented 7 years ago

It doesn't crash with __gshared, but it doesn't give me the colour either.

Also, if I use a bitmap with it it crashes again:

        ALLEGRO_BITMAP* bmp = al_create_bitmap(640,480);
        assert(bmp, "create bitmap failed!");
        scope(exit) al_destroy_bitmap( bmp );
        al_set_target_bitmap(bmp);
        al_clear_to_color(al_map_rgb(255,180,0));

How did you run the program in a debugger? Some one said about using a debugger before your post.

mdparker commented 7 years ago

When you install XCode, you get the clang tools, which includes the lldb debugger. Run lldb <program_name> to debug. You'll want to compile your D programs with -gc (though -g might work as well with lldb, these days, don't know), so add that to a dflags field in your dub configuration.

I've had nothing but trouble trying to bind dynamically with Allegro. These Mac issues are just more in a long line of them. I may end up abandoning this completely and just directing people to DAllegro. Never had issues with like this with any other C library I've created a Derelict binding for.

joelcnz commented 7 years ago

Thanks for your replies. I'll look at DAllegro next, (I have an old version on a Windows computer to update. It didn't have dub back then).