Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » ALLEGRO_NO_ASM incompatibility

This thread is locked; no one can reply to it. rss feed Print
ALLEGRO_NO_ASM incompatibility
Milan Mimica
Member #3,877
September 2003
avatar

I've spent some time on trying to find out why AGL needs a #define ALLEGRO_NO_ASM in order to work with C-only Allegro on Windows and now I reduced the problem to Allegro itself.

1#define ALLEGRO_USE_CONSOLE
2#include <allegro.h>
3#include <stdio.h>
4 
5int main()
6{
7 BITMAP *bmp;
8 int pix;
9 
10 allegro_init();
11 install_keyboard();
12 install_timer();
13 
14 set_color_depth(32);
15 set_gfx_mode(GFX_DIRECTX_WIN, 800, 600, 0, 0);
16 
17 bmp = create_bitmap(200, 200);
18 clear_to_color(bmp, makecol(255, 0, 0));
19 pix = _getpixel32(bmp, 20, 20);
20 printf("%i\n", pix);
21
22 pix = getpixel(bmp, 20, 20);
23 printf("%i\n", pix);
24 
25 readkey();
26 
27 return 0;
28}
29END_OF_MAIN()

This code does not work with C-only Allegro in Release mode. It crashes on _getpixel32() and I think I know why.
_getpixel32() is a inline function, defined in allegro headers, and it depends on ALLEGRO_NO_ASM being defined. End-user programs do not (don't have to and cannot know whether they have to) define ALLEGRO_NO_ASM, which makes the compiler use ASM version of _getpixel32, which does some nasty things...

The problem doesn't show in debug mode because function inlining is disabled, so this is more like a theory and I cannot prove this using a debuger.

If you place #define ALLEGRO_NO_ASM before #include <allegro.h>, it works.

It doesn't crash on getpixel() because it isn't inlined.

edit:edit: apparently, it's MSVC specific, works in mingw

edit: To be more specific, it's a matter of which definition (ASM or C) of bmp_[read|write|unread]_line() is inlined inside _[get|put]_pixel().

Go to: