From 837a03a317fe9c14ff04b44b0330d43cad4ff1d8 Mon Sep 17 00:00:00 2001 From: Anjal Doshi Date: Fri, 20 Oct 2023 15:38:52 -0700 Subject: [PATCH] Fix a crash when undoing AddProcessor Happened when the processor being removed has a merger as the destination node --- .../ProcessorGraph/ProcessorGraphActions.cpp | 18 +++++++++++++++++- .../ProcessorGraph/ProcessorGraphActions.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Processors/ProcessorGraph/ProcessorGraphActions.cpp b/Source/Processors/ProcessorGraph/ProcessorGraphActions.cpp index 214c17a7f..2f13581b7 100644 --- a/Source/Processors/ProcessorGraph/ProcessorGraphActions.cpp +++ b/Source/Processors/ProcessorGraph/ProcessorGraphActions.cpp @@ -54,6 +54,8 @@ AddProcessor::AddProcessor(Plugin::Description description_, destNodeId = destProcessor->getNodeId(); else destNodeId = -1; + + mergerPath = -1; } AddProcessor::~AddProcessor() @@ -90,6 +92,13 @@ bool AddProcessor::perform() if (processor != nullptr) { nodeId = processor->getNodeId(); + + if (destProcessor != nullptr && destProcessor->isMerger()) + { + Merger* merger = (Merger*)destProcessor; + mergerPath = merger->getSourceNode(0)->getNodeId() == nodeId ? 0 : 1; + } + return true; } else @@ -98,7 +107,7 @@ bool AddProcessor::perform() bool AddProcessor::undo() { - LOGD("Undoing ADD for processor ", nodeId); + LOGDD("Undoing ADD for processor ", nodeId); Array processorToDelete; @@ -108,6 +117,13 @@ bool AddProcessor::undo() if (settings != nullptr) delete settings; + GenericProcessor* destProcessor = processor->getDestNode(); + if (mergerPath != -1 && destProcessor != nullptr && destProcessor->isMerger()) + { + Merger* merger = (Merger*)destProcessor; + merger->switchIO(mergerPath); + } + if (processor != nullptr) { settings = processorGraph->createNodeXml(processor, false); diff --git a/Source/Processors/ProcessorGraph/ProcessorGraphActions.h b/Source/Processors/ProcessorGraph/ProcessorGraphActions.h index 29fe6bf2b..8132f8555 100644 --- a/Source/Processors/ProcessorGraph/ProcessorGraphActions.h +++ b/Source/Processors/ProcessorGraph/ProcessorGraphActions.h @@ -65,6 +65,8 @@ class AddProcessor : public UndoableAction bool signalChainIsLoading; int nodeId; + + int mergerPath; Plugin::Description description;