0

i'm trying to making a RGB with integer value (int), my Tesselator function using (int*) and i don't know how to use it for making the RGB. I tried one function that's worked but it's not the same color if i call it 2 time.

the code for make int RGB:

uint32_t colorDoRGB;

void TextRGB()
{
    if (UI::Color::RainbowRED > 0 && UI::Color::RainbowBLUE == 0)
    {
        UI::Color::RainbowRED -= 1;
        UI::Color::RainbowGREEN += 1;
    }
    if (UI::Color::RainbowGREEN > 0 && UI::Color::RainbowRED == 0)
    {
        UI::Color::RainbowGREEN -= 1;
        UI::Color::RainbowBLUE += 1;
    }
    if (UI::Color::RainbowBLUE > 0 && UI::Color::RainbowGREEN == 0)
    {
        UI::Color::RainbowRED += 1;
        UI::Color::RainbowBLUE -= 1;
    }
}

void START_RGB_RAINBOW()
{
    if (UI::Settings::Rainbow)
    {
        colorDoRGB += 15;
        if (colorDoRGB == 30)
        {
            TextRGB();
            colorDoRGB = 0;
        }
    }
}

the code for (int*) when i use it multiple time it's not same color:

int* GetThemeRainbow()
{
    int RAINBOW[3] = { UI::Color::RainbowRED, UI::Color::RainbowGREEN, UI::Color::RainbowBLUE };
    return RAINBOW;
}
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Randy
  • 19
  • 3
  • 2
    `return RAINBOW;` returns dangling pointer, `std::array` might be more appropriate. – Jarod42 Jan 27 '22 at 13:42
  • 1
    `return RAINBOW;` returns a dangling pointer, since the lifetime of `RAINBOW` ends with the function. Though that function is also never called in your code, so it's unclear where or how it is used – UnholySheep Jan 27 '22 at 13:42
  • Does this answer your question? [C++ return array from function](https://stackoverflow.com/questions/8745260/c-return-array-from-function) – JHBonarius Jan 27 '22 at 14:11
  • If `RAINBOW` is not meant to be changed, you could declare it `static`, then returning it would not be dangling anymore. – Remy Lebeau Jan 27 '22 at 19:04

0 Answers0