Bank of lights not lighting up in the right order

I’m trying to bring a module from vcvrack over to metamodule, and am running into an odd issue. I have a bank of 128 SmallLight<RedGreenBlueLight> objects, and when I try to cycle through them one at a time, some of them get skipped over, and some of them light up with the wrong color at the wrong time. See here for a simplified version of the module, to highlight the issue.

The relevant code is as follows:
in the module struct we have

	enum LightId {
/* all the other lights... */
        ENUMS(STATE_LIGHT, 384), // 32 * 4 * 3
		LIGHTS_LEN
	};

Which are turned on one at a time like so:

        for (int i = 0; i < 32 * 4; ++i) {
            if (step == i) {
                // white
                lights[STATE_LIGHT + i * 3 + 0].setBrightnessSmooth(1.f, args.sampleTime);
                lights[STATE_LIGHT + i * 3 + 1].setBrightnessSmooth(1.f, args.sampleTime);
                lights[STATE_LIGHT + i * 3 + 2].setBrightnessSmooth(1.f, args.sampleTime);
            } else {
                lights[STATE_LIGHT + i * 3 + 0].setBrightnessSmooth(0.f, args.sampleTime);
                lights[STATE_LIGHT + i * 3 + 1].setBrightnessSmooth(0.f, args.sampleTime);
                lights[STATE_LIGHT + i * 3 + 2].setBrightnessSmooth(0.f, args.sampleTime);
            }
        }

In the modulewidget constructor, I create the lights like so:

        for (int i = 0; i < 4 * 32; ++i) {
            auto row = i % 32;
            auto col = i / 32;
            auto x = stateX + lightAreaMargin + col * xStep;
            auto y = stateY + lightAreaMargin + row * yStep;
            auto lightIndex = Pascal::STATE_LIGHT + i * 3;
            addChild(createLightCentered<SmallLight<RedGreenBlueLight>>(mm2px(Vec(x, y)), module, lightIndex));
        }

The module compiles fine, and runs as expected in vcvrack. But I’ve tried it on both metamodule 1.6.9 and 2.0.0 and it has this bug.

Sorry for missing this post last week.

So there is an (undocumented) limit of 255 lights, which explains what’s happening.

I tried building your plugin for both api-1.6 and also the v2.0-dev api, and it’s similar for both. One light tracks well (white), but offset by a fixed amount is a red and a blue light. This is because the light value is stored in a uint8_t at some point, so it wraps around (and 256 % 3 is not zero, so the RGB of the white light is spread across two lights).

So, I suppose I will need to raise that limit!

Gotcha. Thanks for looking into it, I wondered if it might be something like that. I’ll switch them to solid color lights instead or rgb in the meantime, that should bring me under the limit.