From 6c8e7dd27db7f8664c664cd1bdeb11df815308a7 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 20 Feb 2025 18:21:04 -0500 Subject: [PATCH] Better erase in the lag handler. Oops (#182) --- include/sst/basic-blocks/dsp/LagCollection.h | 14 ++++++++++---- tests/dsp_tests.cpp | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/sst/basic-blocks/dsp/LagCollection.h b/include/sst/basic-blocks/dsp/LagCollection.h index fa00611..6a7918d 100644 --- a/include/sst/basic-blocks/dsp/LagCollection.h +++ b/include/sst/basic-blocks/dsp/LagCollection.h @@ -95,11 +95,17 @@ template struct LagCollection void processAll() { - for (auto &lag : activeSet) + for (auto it = activeSet.begin(); it != activeSet.end();) { - lag.process(); - if (!lag.lag.isActive()) - activeSet.removeFromActive(lag); + it->process(); + if (!it->lag.isActive()) + { + it = activeSet.erase(it); + } + else + { + ++it; + } } } diff --git a/tests/dsp_tests.cpp b/tests/dsp_tests.cpp index 46493fa..e87b7cb 100644 --- a/tests/dsp_tests.cpp +++ b/tests/dsp_tests.cpp @@ -1349,7 +1349,9 @@ TEST_CASE("Lag Collection", "[dsp]") lags.setTarget(3, 0.7 + lv * 0.72, &vals[3]); } lags.processAll(); - if (i < 14) + if (i == 0) + REQUIRE(lags.activeSet.activeCount == 0); + else if (i < 14 && i >= 1) REQUIRE(lags.activeSet.activeCount == 1); else REQUIRE(lags.activeSet.activeCount == 2);