Allegro 5 C / C ++: Problem with colors

0

I'm using allegro 5, and I read that to create colors just use al_map_rgb or al_color_html , so I made a map to easily access multiple colors:

#include "allegro5\allegro.h"
#include "allegro5\allegro_color.h"

int main()
{
    al_init();

    map<string, ALLEGRO_COLOR> color;
    color["black"] = al_color_html("#000000");
    color["gray"] = al_color_html("#808080");
    color["silver"] = al_color_html("#c0c0c0");
    color["white"] = al_color_html("#ffffff");
    color["maroon"] = al_color_html("#800000");
    color["red"] = al_color_html("#ff0000");
    color["olive"] = al_color_html("#808000");
    color["yellow"] = al_color_html("#ffff00");
    color["green"] = al_color_html("#008000");
    color["lime"] = al_color_html("#00ff00");
    color["teal"] = al_color_html("#008080");
    color["aqua"] = al_color_html("#00ffff");
    color["naavi"] = al_color_html("#0000ff");
    color["blue"] = al_color_html("#000080");
    color["purple"] = al_color_html("#800080");
    color["fuchsia"] = al_color_html("#ff00ff");

    return 0;
}

But the program crashes when I test. So by testing, I discovered that if I only use 6 colors, my program performs perfectly:

#include "allegro5\allegro.h"
#include "allegro5\allegro_color.h"

int main()
{
    al_init();

    map<string, ALLEGRO_COLOR> color;
    color["black"] = al_color_html("#000000");
    color["gray"] = al_color_html("#808080");
    color["silver"] = al_color_html("#c0c0c0");
    color["white"] = al_color_html("#ffffff");
    color["maroon"] = al_color_html("#800000");
    color["red"] = al_color_html("#ff0000");

    return 0;
}

But if I add another color, it will crash again:

#include "allegro5\allegro.h"
#include "allegro5\allegro_color.h"

int main()
{
    al_init();

    map<string, ALLEGRO_COLOR> color;
    color["black"] = al_color_html("#000000");
    color["gray"] = al_color_html("#808080");
    color["silver"] = al_color_html("#c0c0c0");
    color["white"] = al_color_html("#ffffff");
    color["maroon"] = al_color_html("#800000");
    color["red"] = al_color_html("#ff0000");
    color["blue"] = al_color_html("#000080");

    return 0;
}

In the same way, if I use a for to generate colors, without saving any variable, after the seventh repetition the program crashes.

This works:

for (int i = 0; i < 6; i++)
{
    al_color_html("#000080");
}

That's not it:

for (int i = 0; i < 7; i++)
{
    al_color_html("#000080");
}

However, if I do this:

for (int i = 1; true; i++)
{
    cout << i << " ";
    al_color_html("#000080");
}

I have output 1 2 3 4 5 ... 57 58 59 , and if I do this:

for (int i = 1; true; i++)
{
    al_color_html("#000080");
    cout << i << " ";
}

I have output 1 2 3 4 5 ... 15 16 17

Note: The error also occurs with al_map_rgb , however I can run the command more often

    
asked by anonymous 15.06.2017 / 00:05

1 answer

0

The answer is quite simple: update Allegro and MinGW .

    
16.06.2017 / 01:02