bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange behavior with color_content()


From: Bryan Christ
Subject: Strange behavior with color_content()
Date: Wed, 5 Feb 2020 12:05:43 -0600

In order to find an unused color in the ncurses palette, I run a simple loop test looking for a free color.  The code is basically something like this:

color_num = COLOR_WHITE + 1;    // skip built-in colors
for(;;)
{
    color_content(color_num, &r, &g, &b);

    if((r + g + b) == 0) break;

    color_num++;
}

Now the odd thing is that this works except when the value of "color_num" is a multiple of 8.  When "color_num" is a multiple of 8, it incorrectly returns zero for the r, g, and b values even when the color is already used.  I know that the allegedly free "color_num" is actually used because after breaking from the loop (when r + g + b equals 0) I immediately call init_color() with "color_num" and set the desired RGB values.  When I do this, it affects certain colors already on the screen.  In most cases the "tput-colorcube" output is on the screen and so every 8th cell of the cubes are affected.  I dropped a printf into the successive calls to this block of code and output is shown below.  Since there are no other calls to init_color() in my code, it seems like color_content() is failing sometimes.  In my actual code, I check the return value on both color_content() and init_color() and neither one of them return ERR indicating a problem.

fprintf(stderr, "color num %d : %d, %d, %d\n\r", color_num, r, g, b);

color num 8 : 0, 0, 0
color num 16 : 0, 0, 0
color num 24 : 0, 0, 0
color num 32 : 0, 0, 0
color num 40 : 0, 0, 0
color num 48 : 0, 0, 0
color num 56 : 0, 0, 0
color num 64 : 0, 0, 0
color num 72 : 0, 0, 0
color num 80 : 0, 0, 0
color num 88 : 0, 0, 0
color num 96 : 0, 0, 0
color num 104 : 0, 0, 0
color num 112 : 0, 0, 0
color num 120 : 0, 0, 0
color num 128 : 0, 0, 0
color num 136 : 0, 0, 0
color num 144 : 0, 0, 0
color num 152 : 0, 0, 0
color num 160 : 0, 0, 0
color num 168 : 0, 0, 0
color num 176 : 0, 0, 0
color num 184 : 0, 0, 0
color num 192 : 0, 0, 0
color num 200 : 0, 0, 0
color num 208 : 0, 0, 0
color num 216 : 0, 0, 0
color num 224 : 0, 0, 0
color num 232 : 0, 0, 0

--
Bryan
<><

reply via email to

[Prev in Thread] Current Thread [Next in Thread]