From 86fbd84cf60086f9f648f7941ad42ce2f8bfc052 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 31 Oct 2021 12:38:07 +0000 Subject: [PATCH] Fix crash on close, do not setup worker threads Signed-off-by: falkTX --- lv2export/test.cpp | 11 +++++++++++ src/CardinalPlugin.cpp | 15 ++++++++++++++- src/CardinalUI.cpp | 7 ++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lv2export/test.cpp b/lv2export/test.cpp index fc323b8..67f0552 100644 --- a/lv2export/test.cpp +++ b/lv2export/test.cpp @@ -108,5 +108,16 @@ int main() i+1, q->name.c_str(), q->getDescription().c_str(), q->unit.c_str(), q->minValue, q->maxValue, q->defaultValue); } + + Module::ProcessArgs args = { + 48000.0f, + 1.0f / 48000.0f, + 0 + }; + for (int i=0; i<96000; ++i) + { + module->process(args); + ++args.frame; + } return 0; } diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index 7b4556f..65bbdcd 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -94,7 +94,7 @@ struct Initializer #ifdef __MOD_DEVICES__ settings::threadCount = 3; #else - settings::threadCount = 1; + settings::threadCount = 0; #endif system::init(); @@ -768,7 +768,10 @@ protected: const MutexLocker cml(fDeviceMutex); if (fCurrentAudioDevice != nullptr) + { + rack::contextSet(context); fCurrentAudioDevice->onStartStream(); + } } } @@ -778,7 +781,10 @@ protected: const MutexLocker cml(fDeviceMutex); if (fCurrentAudioDevice != nullptr) + { + rack::contextSet(context); fCurrentAudioDevice->onStopStream(); + } } delete[] fAudioBufferOut; @@ -866,6 +872,13 @@ protected: } } + void sampleRateChanged(const double newSampleRate) override + { + rack::contextSet(context); + rack::settings::sampleRate = newSampleRate; + context->engine->setSampleRate(newSampleRate); + } + // ------------------------------------------------------------------------------------------------------- private: diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index 1958d32..e5e0266 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -129,10 +129,12 @@ public: ~CardinalUI() override { - const ScopedContext sc(this); + rack::contextSet(fContext); delete fContext->window; fContext->window = nullptr; + + rack::contextSet(nullptr); } void onNanoDisplay() override @@ -513,9 +515,8 @@ protected: if (filename == nullptr) return; - // we cannot lock here - // const ScopedContext sc(this); rack::contextSet(fContext); + WindowParametersRestore(fContext->window); fContext->patch->loadAction(filename); }