ALLEGRO_COLOR in array
lCoopsl

I'm experiencing a strange issue of ALLEGRO_COLOR definitions having their values disappear when initialized in an array. It seems like it has something to do with function scope.

#SelectExpand
1ALLEGRO_COLOR test[1] = { 2 al_map_rgb(50,50,50), 3}; 4 5int main(int argc, char **argv) { 6 7 //Allegro initialization snip 8 9 std::cout << test[0].r << std::endl; 10 11 return 0; 12}

cout returns '0'.

However,

#SelectExpand
1int main(int argc, char **argv) { 2 3 //Allegro initialization snip 4 5 ALLEGRO_COLOR test[1] = { 6 al_map_rgb(50,50,50), 7 }; 8 9 std::cout << test[0].r << std::endl; 10 11 return 0; 12}

Properly returns the float value.

Any ideas whats happening here?

Elias

You cannot use al_map_rgb (or any other Allegro functions) before you call al_init.

Edgar Reynaldo

The problem is not initialization in an array, rather it is because of initialization before al_init is called.

ALLEGRO_COLOR mycol() {
   return al_map_rgb(255,196,127);
}

int main(int argc , char** argv) {
   if (!al_init()) {return 0;}
   ALLEGRO_COLOR c = mycol();/// works fine

   return 0;
}

lCoopsl

Thanks for the response, sometimes its simpler than you think I guess.

Thread #617263. Printed from Allegro.cc