Browse Source

Don't assert if ModuleLightWidget accesses out of bounds lights, simply set brightness to 0. If module is bypassed, set brightness to 0.

tags/v2.0.2
Andrew Belt 2 years ago
parent
commit
02cceecc3e
1 changed files with 15 additions and 11 deletions
  1. +15
    -11
      src/app/ModuleLightWidget.cpp

+ 15
- 11
src/app/ModuleLightWidget.cpp View File

@@ -107,17 +107,21 @@ void ModuleLightWidget::destroyTooltip() {
void ModuleLightWidget::step() {
std::vector<float> brightnesses(baseColors.size());

if (module && firstLightId >= 0) {
assert((int) module->lights.size() >= firstLightId + (int) baseColors.size());

for (size_t i = 0; i < baseColors.size(); i++) {
float b = module->lights[firstLightId + i].getBrightness();
if (!std::isfinite(b))
b = 0.f;
b = math::clamp(b, 0.f, 1.f);
// Because LEDs are nonlinear, this seems to look more natural.
b = std::sqrt(b);
brightnesses[i] = b;
int lastLightId = firstLightId + (int) baseColors.size();
if (module) {
if (module->isBypassed()) {
// Leave lights off
}
else if (0 <= firstLightId && lastLightId <= (int) module->lights.size()) {
for (size_t i = 0; i < baseColors.size(); i++) {
float b = module->lights[firstLightId + i].getBrightness();
if (!std::isfinite(b))
b = 0.f;
b = math::clamp(b, 0.f, 1.f);
// Because LEDs are nonlinear, this seems to look more natural.
b = std::sqrt(b);
brightnesses[i] = b;
}
}
}
else {


Loading…
Cancel
Save