From 50c1999875b961406171afe5d98671bc6b785a99 Mon Sep 17 00:00:00 2001 From: wangshaohui <97082645@qq.com> Date: Wed, 24 Nov 2021 17:39:36 +0800 Subject: [PATCH] obs-vst: Use deleteLater on editorWidget to prevent crash (#92) * obs-vst: Fix crash that we should delete widget later * obs-vst: Make sure effEditClose won't be called again * clang format Co-authored-by: wangshaohui --- VSTPlugin.cpp | 14 ++++++++------ headers/VSTPlugin.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/VSTPlugin.cpp b/VSTPlugin.cpp index 5cfdc4e3..999f3206 100644 --- a/VSTPlugin.cpp +++ b/VSTPlugin.cpp @@ -170,7 +170,8 @@ bool VSTPlugin::isEditorOpen() void VSTPlugin::openEditor() { if (effect && !editorWidget) { - editorWidget = new EditorWidget(nullptr, this); + editorOpenned = true; + editorWidget = new EditorWidget(nullptr, this); editorWidget->buildEffectContainer(effect); if (sourceName.empty()) { @@ -189,13 +190,14 @@ void VSTPlugin::openEditor() void VSTPlugin::closeEditor() { - if (effect) { - effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0); - } - if (editorWidget) { + if (effect && editorOpenned) { + editorOpenned = false; + effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0); + } + editorWidget->close(); - delete editorWidget; + editorWidget->deleteLater(); editorWidget = nullptr; } } diff --git a/headers/VSTPlugin.h b/headers/VSTPlugin.h index 1d8aa7f7..2178acbc 100644 --- a/headers/VSTPlugin.h +++ b/headers/VSTPlugin.h @@ -45,7 +45,8 @@ class VSTPlugin : public QObject { float **inputs; float **outputs; - EditorWidget *editorWidget = nullptr; + EditorWidget *editorWidget = nullptr; + bool editorOpenned = false; AEffect *loadEffect();