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);