From 724b35be951d6306ed7e2e7bc1e4cc7a00b4f332 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 13 Aug 2024 15:12:02 -0400 Subject: [PATCH] Define destructor for Scripting --- include/scripting.h | 3 ++- src/scriptapi/scripting.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/scripting.h b/include/scripting.h index e2bfb1ff..c08bbd74 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -30,8 +30,9 @@ class Scripting { public: Scripting(MainWindow *mainWindow); - static void stop(); + ~Scripting(); static void init(MainWindow *mainWindow); + static void stop(); static void populateGlobalObject(MainWindow *mainWindow); static QJSEngine *getEngine(); static void invokeAction(int actionIndex); diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index 95a4325f..71fbabca 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -24,11 +24,6 @@ const QMap callbackFunctions = { Scripting *instance = nullptr; void Scripting::stop() { - if (!instance) return; - instance->engine->setInterrupted(true); - qDeleteAll(instance->imageCache); - delete instance->engine; - delete instance->scriptUtility; delete instance; instance = nullptr; } @@ -54,6 +49,13 @@ Scripting::Scripting(MainWindow *mainWindow) { this->scriptUtility = new ScriptUtility(mainWindow); } +Scripting::~Scripting() { + this->engine->setInterrupted(true); + qDeleteAll(this->imageCache); + delete this->engine; + delete this->scriptUtility; +} + void Scripting::loadModules(QStringList moduleFiles) { for (QString filepath : moduleFiles) { QString validPath = Project::getExistingFilepath(filepath);