Skip to content

Commit

Permalink
Fix a crash when undoing AddProcessor
Browse files Browse the repository at this point in the history
Happened when the processor being removed has a merger as the destination node
  • Loading branch information
anjaldoshi committed Oct 20, 2023
1 parent 384944f commit 837a03a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Source/Processors/ProcessorGraph/ProcessorGraphActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ AddProcessor::AddProcessor(Plugin::Description description_,
destNodeId = destProcessor->getNodeId();
else
destNodeId = -1;

mergerPath = -1;
}

AddProcessor::~AddProcessor()
Expand Down Expand Up @@ -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
Expand All @@ -98,7 +107,7 @@ bool AddProcessor::perform()

bool AddProcessor::undo()
{
LOGD("Undoing ADD for processor ", nodeId);
LOGDD("Undoing ADD for processor ", nodeId);

Array<GenericProcessor*> processorToDelete;

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Source/Processors/ProcessorGraph/ProcessorGraphActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class AddProcessor : public UndoableAction
bool signalChainIsLoading;

int nodeId;

int mergerPath;

Plugin::Description description;

Expand Down

0 comments on commit 837a03a

Please sign in to comment.