From 770126c6338d6a246517c424921e9517222f9a7f Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sun, 18 Feb 2024 22:49:45 +0000 Subject: [PATCH] Fix bug when recreating AudioGraph after destroy() --- source/src/core/graph.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/src/core/graph.cpp b/source/src/core/graph.cpp index 99da48df..144eb227 100644 --- a/source/src/core/graph.cpp +++ b/source/src/core/graph.cpp @@ -168,18 +168,28 @@ void AudioGraph::clear() void AudioGraph::destroy() { - AudioOut_Abstract *audioout = (AudioOut_Abstract *) this->output.get(); - if (audioout) - { - audioout->destroy(); - } - if (shared_graph == this) + // Clear output when destroyed to ensure that multiply destroy() calls won't crash + if (this->output) { - shared_graph = nullptr; + AudioOut_Abstract *audioout = (AudioOut_Abstract *) this->output.get(); + if (audioout) + { + audioout->destroy(); + } + if (shared_graph == this) + { + shared_graph = nullptr; + } + this->output = nullptr; } } -AudioGraph::~AudioGraph() { this->destroy(); } +AudioGraph::~AudioGraph() +{ + // When the AudioGraph is deallocated (which happens automatically at the end of a Python script), + // ensure it is destroyed. + this->destroy(); +} void AudioGraph::wait(float time) {