I have a plugin that draws an array of polygons. The fill color of each is either white, grey, or a color computed based off the plugin state. Each polygon can have a unique color, though, in practice there should probably only be a couple dozen unique colors. There are only 50 or so polygons. To draw them, I simply iterate over the array and make the expected nanovg calls in the widgets draw
method.
The grey and white fills are handled correctly; however, the uniquely computed colors are not: every polygon is filled with the same color; which color that is depends on the state, but it’s always one of the unique colors I expect.
I’ve debugged this draw call numerous ways: I’ve confirmed that for a given state, I have a map of <Polygon, NVGcolor> that contains the expected number of unique NVColors. I simply apply the fill like so:
for (const auto &poly : polygons)
{
nvgStrokeColor(vg, nvgRGBf(0.88, 0.88, 0.88));
nvgStrokeWidth(vg, 1.0);
nvgLineJoin(vg, NVG_MITER);
// Start drawing a path
nvgBeginPath(vg);
[...]
DEBUG("filling color: %s", nvcolor_to_string(fillColors[poly]).c_str());
// Close the path and fill
nvgClosePath(vg);
nvgFillColor(vg, fillColors[poly]);
nvgStroke(vg);
nvgFill(vg);
and I’ve confirmed that more than one color is set:
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.71, 0.79, 0.82
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.71, 0.79, 0.82
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.71, 0.79, 0.82
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.90, 1.00, 0.90
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.71, 0.79, 0.82
[7.115 debug src/AmB-Tonnetz.cpp:376 draw] filling color: 0.71, 0.79, 0.82
However, all polys remain the same color. Are there any tricks to debugging this further? FWIW, I have tried filling with gradients but the result is the same.
This is compiled on darwin, arm_64 using clang.
EDIT: “However, all polys remain the same color.” > All polys not clicked and therefore grey. The grey fill works as expected.
EDIT2: for anyone coming to this thread: there’s something in the color computation code that seems to clobber the nvgColorFill values. I’m fairly mystified since I don’t manage any allocations manually and my 3 lines of eigen code are stock. I might just rewrite this whole thing in rust.