[A5]
wiseguy

I'm having trouble with testing on Ubuntu inside a virtual machine and I am trying to figure out if the problem is with my VM setup or something else. I am running Ubuntu 10.10 with Allegro 5.0 installed from SVN.

Whenever I try to run the program here is what is reported in the terminal window:

failed to create drawable
X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
Major opcode of failed request: 55 (X_CreateGC)
Resource id in failed request: 0x4400002
Serial number of failed request: 25
Current serial number in output stream: 27

As of right now I'm only setting a display and drawing a test image to it. I see that the linux install has the allegro_main library, so does that mean I need to use END_OF_MAIN()? I had thought this was only needed on OSX.

Here is the source code:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4 5int main(int argc, char *argv[]) 6{ 7 ALLEGRO_DISPLAY *scr; 8 ALLEGRO_BITMAP *bmp; 9 ALLEGRO_EVENT_QUEUE *eventQueue; 10 ALLEGRO_EVENT retEvent; 11 bool exitFlag = false; 12 13 al_init(); 14 al_init_image_addon(); 15 al_install_keyboard(); 16 eventQueue = al_create_event_queue(); 17 al_register_event_source(eventQueue, al_get_keyboard_event_source()); 18 scr = al_create_display(800,600); 19 if (scr==NULL) 20 { 21 printf("Could not create display at 800x600"); 22 return 1; 23 } 24 al_clear_to_color(al_map_rgb(0,0,0)); 25 bmp = al_load_bitmap("test.jpg"); 26 if (bmp!=NULL) 27 al_draw_scaled_bitmap(bmp, 0, 0, al_get_bitmap_width(bmp), al_get_bitmap_height(bmp), 0, 0, 800, 600, 0); 28 while (!exitFlag) 29 { 30 al_flip_display(); 31 if (!al_event_queue_is_empty(eventQueue)) 32 { 33 al_get_next_event(eventQueue, &retEvent); 34 if (retEvent.type == ALLEGRO_EVENT_KEY_CHAR) 35 { 36 if (retEvent.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 37 exitFlag = true; 38 } 39 } 40 } 41}

Is this just because I'm running inside a VM?

WG

Thomas Fjellstrom

Its most likely because you're running inside a VM. See if you can't setup OpenGL pass-through for your VM, as Allegro 5 has a hard dependency on OpenGL. It will not work without it.

Evert
wiseguy said:

I see that the linux install has the allegro_main library, so does that mean I need to use END_OF_MAIN()? I had thought this was only needed on OSX.

You never need END_OF_MAIN(). Allegro 5's magic main doesn't need it.
Yes, it's only needed on OS X, so on Linux allegro_main does nothing. I tend to link it in blindly, which means I can use the same build script on Linux as on OS X, which is nice (not essential though).

wiseguy

Thanks for the responses. My test program works fine on my kids' PC which is also running Ubuntu 10.10, so the problem has to be the virtual machine. I've been trying to figure out the opengl passthrough but so far VMWare seems to only support that for Windows guests.

X-G
Evert said:

You never need END_OF_MAIN() [...] Yes, it's only needed on OS X

???

Arthur Kalliokoski

Apparently, "You" meant WiseGuy.

Thomas Fjellstrom

END_OF_MAIN is never needed or is even valid. liballegro_main is only needed on OSX.

Evert
Quote:

???

Linking with allegro_main.

X-G

Why is allegro_main required at all, anyway?

wiseguy

I have since installed Linux as my main OS, so the above question no longer holds. The intersting thing will be if I decide to install windows on this host as a VM and cross compile my sources. Too bad I can't test it out on Mac OSX inside a VM.

WG

Evert
X-G said:

Why is allegro_main required at all, anyway?

The message loop that gets messages from the OS needs to run from the main thread, meaning al_init() cannot return to the caller if we want to receive messages from the OS (which we obviously do). The easiest thing to do is to have our own main() function and call the user main from a separate thread.

If there's a way around that, I'm sure we're all glad to hear it. SDL does (or at least did) more or less the same thing though, which suggests that there isn't.

Elias
X-G said:

Why is allegro_main required at all, anyway?

It only has any purpose under OSX - for Windows and Linux it's a completely empty library as far as I know. In OSX, allegro_main.dylib basically looks like this:

int main() {
    [[[NSApplication alloc]init]run];
}

-OnAppLaunched {
    pthreads_run(user_main);
}

That way an Allegro app is a normal Cocoa App, with objective C stuff and doing all events handling in the main thread (it seems it's not even possible to do things in any other way). It leaves no room for a C-style main() function in user code, so we fake that by having a "#define main user_main" in allegro.h and starting a separate thread when the Cocoa app is launched which runs that user_main.

Now, why did we put this in a separate allegro_main.dylib and not into the main allegro.dylib? The reason is that sometimes you can't rename the main() function. E.g. when you don't use C/C++ and therefore never include allegro.h. In such cases you would still use allegro.dylib (which does not have any main() function in it) and exclude allegro_main.dylib. Then from your real main you do whatever is needed and then use al_run_main to run the user code. (The Python wrapper does this for example.)

Thread #606128. Printed from Allegro.cc