From 9e1604947c8401b637d501fea4453e1f58fb30bb Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Sun, 1 Dec 2024 17:31:03 +0100 Subject: [PATCH] Revert change object impl change that causes crash --- Source/Objects/ImplementationBase.cpp | 57 ++++++++++++--------------- Tests/Tests.cpp | 2 +- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Source/Objects/ImplementationBase.cpp b/Source/Objects/ImplementationBase.cpp index a5a15b1d1..e8e6013d0 100644 --- a/Source/Objects/ImplementationBase.cpp +++ b/Source/Objects/ImplementationBase.cpp @@ -128,19 +128,40 @@ ObjectImplementationManager::ObjectImplementationManager(pd::Instance* processor void ObjectImplementationManager::handleAsyncUpdate() { - - objectImplementationLock.enter(); + SmallArray> allCanvases; + SmallArray> allImplementations; + UnorderedSet allObjects; + + pd->setThis(); + + pd->lockAudioThread(); + for (auto* topLevelCnv = pd_getcanvaslist(); topLevelCnv; topLevelCnv = topLevelCnv->gl_next) { + allCanvases.add({ topLevelCnv, topLevelCnv }); + getSubCanvases(topLevelCnv, topLevelCnv, allCanvases); + } + + for (auto& [top, glist] : allCanvases) { + for (t_gobj* y = glist->gl_list; y; y = y->g_next) { + auto const* name = pd::Interface::getObjectClassName(&y->g_pd); + if (ImplementationBase::hasImplementation(name)) { + allImplementations.add({ top, y }); + allObjects.insert(y); + } + } + } + pd->unlockAudioThread(); + for (auto it = objectImplementations.cbegin(); it != objectImplementations.cend();) { auto& [ptr, implementation] = *it; - if (targetObjects.contains(ptr)) { + if (allObjects.contains(ptr)) { it = objectImplementations.erase(it); // Erase and move iterator forward. } else { ++it; } } - for (auto& [cnv, obj] : targetImplementations) { + for (auto& [cnv, obj] : allImplementations) { if (!objectImplementations.count(obj)) { auto const name = String::fromUTF8(pd::Interface::getObjectClassName(&obj->g_pd)); objectImplementations[obj] = std::unique_ptr(ImplementationBase::createImplementation(name, obj, cnv, pd)); @@ -148,37 +169,11 @@ void ObjectImplementationManager::handleAsyncUpdate() objectImplementations[obj]->update(); } - objectImplementationLock.exit(); } void ObjectImplementationManager::updateObjectImplementations() { - pd->enqueueFunctionAsync([this](){ - SmallArray> allCanvases; - SmallArray> allImplementations; - UnorderedSet allObjects; - - for (auto* topLevelCnv = pd_getcanvaslist(); topLevelCnv; topLevelCnv = topLevelCnv->gl_next) { - allCanvases.add({ topLevelCnv, topLevelCnv }); - getSubCanvases(topLevelCnv, topLevelCnv, allCanvases); - } - - for (auto& [top, glist] : allCanvases) { - for (t_gobj* y = glist->gl_list; y; y = y->g_next) { - auto const* name = pd::Interface::getObjectClassName(&y->g_pd); - if (ImplementationBase::hasImplementation(name)) { - allImplementations.add({ top, y }); - allObjects.insert(y); - } - } - } - - objectImplementationLock.enter(); - targetImplementations = allImplementations; - targetObjects = allObjects; - objectImplementationLock.exit(); - triggerAsyncUpdate(); - }); + triggerAsyncUpdate(); } void ObjectImplementationManager::getSubCanvases(t_canvas* top, t_canvas* canvas, SmallArray>& allCanvases) diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index c63b8ba63..b9858440a 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -13,7 +13,7 @@ void runTests(PluginEditor* editor) HelpFileFuzzTest helpfileFuzzer(editor); UnitTestRunner runner; - //runner.runTests({&objectFuzzer, &helpfileFuzzer}, 1); + runner.runTests({&objectFuzzer, &helpfileFuzzer}, 1); }); testRunnerThread.detach(); }