Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ALLEGRO_COLOR in array

This thread is locked; no one can reply to it. rss feed Print
ALLEGRO_COLOR in array
lCoopsl
Member #16,804
February 2018

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
Member #358
May 2000

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

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Member #8,592
May 2007
avatar

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
Member #16,804
February 2018

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

Go to: