![]() |
|
[A5] al_map_rgb crash? |
Dario ff
Member #10,065
August 2008
![]() |
Alright, I haven't been using Allegro for a while but this is just plain weird. I've been commenting almost everything out and even this bare bones code crashes: 1#include "allegro5/allegro.h"
2#include "allegro5/allegro_image.h"
3#include <iostream>
4
5void mergeGIA(ALLEGRO_BITMAP *bg, ALLEGRO_BITMAP *fg, const char *str) {
6 ALLEGRO_BITMAP *out=al_create_bitmap(1024, 1024);
7 int bg_h, bg_w, bg_x, bg_y;
8 al_set_target_bitmap(out);
9 al_clear_to_color(al_map_rgba_f(0,0,0,0));
10
11 bg_w=1024;
12 bg_h=1024;
13
14 for (bg_x = 0; bg_x < bg_w; bg_x++)
15 {
16 printf("%d\n", bg_x);
17 for (bg_y = 0; bg_y < bg_h; bg_y++)
18 {
19 ALLEGRO_COLOR c=al_map_rgb(255, 255, 255);
20 }
21 }
22
23 al_save_bitmap(str, out);
24 al_destroy_bitmap(out);
25}
26
27
28
29
30int main(int argc, char *argv[])
31{
32 if(!al_init()) {
33 printf("Failed to initialize Allegro!\n");
34 return -1;
35 }
36
37 al_init_image_addon();
38 mergeGIA(NULL, NULL, "out.png");
39 return 0;
40}
I know that code alone looks pointless, it's just that I removed all irrelevant code that isn't causing a crash. When I run it it only goes up to pixel 508 and crashes. If I comment out al_map_rgb it goes through just fine. What am I doing wrong? In the real code, if I just take out al_map_rgb out of the loop and assign it to c, then feed al_put_pixel the color c, it doesn't crash at all. Using the Allegro 5.0.6 monolith build. EDIT: Bonus round, modifying directly the ALLEGRO_COLOR paremeters instead of using al_map_rgb causes no crashes. Did I just stumble upon a really obscure bug? TranslatorHack 2010, a human translation chain in a.cc. |
Trent Gamblin
Member #261
April 2000
![]() |
Do you call al_init anywhere?
|
Dario ff
Member #10,065
August 2008
![]() |
It's there hidden by an if. Line #32. TranslatorHack 2010, a human translation chain in a.cc. |
SiegeLord
Member #7,827
October 2006
![]() |
Does it crash with al_map_rgb_f and al_get_pixel? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Dario ff
Member #10,065
August 2008
![]() |
Trying the following code. #include "allegro5/allegro.h" int main(int argc, char *argv[]) { al_init(); for (int i=0; i<600000; i++) { al_map_rgb_f(1, 1, 1); } return 0; } With 500000 it works fine, but with 600000 it throws off the 0xC00000FD exception. Same deal with al_map_rgb and al_map_rgb_f. The same kind of crash also happens with al_get_pixel. 1#include "allegro5/allegro.h"
2#include "allegro5/allegro_image.h"
3
4int main(int argc, char *argv[])
5{
6 al_init();
7 al_init_image_addon();
8
9 ALLEGRO_BITMAP *bmp=al_load_bitmap("test.png");
10
11 for (int i=0; i<600000; i++) {
12 al_get_pixel(bmp, 0, 0);
13 }
14
15 return 0;
16}
Is it a stack memory error? But I'm not even using it! Unless I have the wrong understanding of it. EDIT: Well it seems like a stack memory error indeed. If I separate the for loop into another function(0 to 100000) and call it several times, it won't crash. What might be the cause of these functions causing this kind of error? EDIT2: More concrete example of what I mean, if I make my own wrapper function around it: 1#include "allegro5/allegro.h"
2#include "allegro5/allegro_image.h"
3
4ALLEGRO_COLOR wrapper_al_map_rgb(int r, int g, int b) {
5 return al_map_rgb(r, g, b);
6}
7
8
9int main(int argc, char *argv[])
10{
11 al_init();
12
13 for (int i=0; i<600000; i++) {
14 //ALLEGRO_COLOR c=al_map_rgb(255, 255, 255); <-- Crashes
15 ALLEGRO_COLOR c=wrapper_al_map_rgb(255, 255, 255);
16 }
17
18 return 0;
19}
It doesn't crash with a wrapper. TranslatorHack 2010, a human translation chain in a.cc. |
someone972
Member #7,719
August 2006
![]() |
I tried the first example in your first post, but even with more than 1000x as many iterations it did not crash. I am using 5.04 though. What compiler and compiler version are you using? ______________________________________ |
SiegeLord
Member #7,827
October 2006
![]() |
Functions that return structs have a bizzare calling convention that differs between compilers (MSVC vs old GCC vs new GCC). Usually you run into this when you're using a different complier to compile your program vs the one that was used to compile the library. So yes... the exact version of your compiler as well as the binary source might be of use. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Dario ff
Member #10,065
August 2008
![]() |
Yeah I see the problem now, it seems I haven't updated MinGW since 3.4.5 and the monolith builds for that version stopped long ago apparently. I'll update and post back here if I get it working. It seems at the time I didn't care and just got one of the newer Allegro builds anyway. Sorry for the problem, it's just the first time I run into this sort of error. Thanks for the help. TranslatorHack 2010, a human translation chain in a.cc. |
Elias
Member #358
May 2000
|
When this came up last time one idea was to add alternate functions to Allegro 5: ALLEGRO_COLOR *al_make_rgba_f(ALLEGRO_COLOR *c, float r, float g, float b, float a); And so on. Instead of returning a struct, this would just returns a pointer and write into the struct. Using it in C/C++ wouldn't be much more difficult: ALLEGRO_COLOR c; al_draw_line(0, 0, 10, 10, *al_make_rgba_f(&c, 1, 1, 1, 1), 1); In hindsight it probably was a bad idea having struct parameters at all (i.e. al_draw_line should take a pointer to ALLEGRO_COLOR not a full struct). But nothing we can do about that now. -- |
Dario ff
Member #10,065
August 2008
![]() |
I've updated to gcc version 4.6.2 and downloaded the MinGW 4.6.2 binaries. Now there's no crash no matter how much I try. First time I ever come across this sort of problem, I didn't think there would be so much trouble with using clashing versions as it worked fine; so sorry for bringing up a non-existent issue. TranslatorHack 2010, a human translation chain in a.cc. |
|