Fix crash on shutdown due to lifetime of scripts

This commit is contained in:
Brad Davis 2016-01-12 12:40:02 -08:00
parent 8619be28ef
commit 55af5eaf06
3 changed files with 12 additions and 4 deletions

View file

@ -171,9 +171,6 @@ void ScriptEngine::runInThread() {
// when the thread is finished, add thread to the deleteLater queue
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
// when the thread is finished, add scriptEngine to the deleteLater queue
connect(workerThread, &QThread::finished, this, &ScriptEngine::deleteLater);
moveToThread(workerThread);
// Starts an event loop, and emits workerThread->started()

View file

@ -112,6 +112,8 @@ void ScriptEngines::shutdownScripting() {
scriptEngine->waitTillDoneRunning();
qCDebug(scriptengine) << "done waiting on script:" << scriptName;
scriptEngine->deleteLater();
// If the script is stopped, we can remove it from our set
i.remove();
}
@ -343,6 +345,10 @@ ScriptEngine* ScriptEngines::loadScript(const QString& scriptFilename, bool isUs
scriptEngine = new ScriptEngine(NO_SCRIPT, "", true);
scriptEngine->setUserLoaded(isUserLoaded);
connect(scriptEngine, &ScriptEngine::doneRunning, this, [scriptEngine] {
scriptEngine->deleteLater();
}, Qt::QueuedConnection);
if (scriptFilename.isNull()) {
launchScriptEngine(scriptEngine);
@ -431,5 +437,8 @@ QString ScriptEngines::getPreviousScriptLocation() const {
}
void ScriptEngines::setPreviousScriptLocation(const QString& previousScriptLocation) {
_previousScriptLocation.set(previousScriptLocation);
if (_previousScriptLocation.get() != previousScriptLocation) {
_previousScriptLocation.set(previousScriptLocation);
emit previousScriptLocationChanged();
}
}

View file

@ -30,6 +30,7 @@ class ScriptEngines : public QObject, public Dependency {
Q_PROPERTY(ScriptsModel* scriptsModel READ scriptsModel CONSTANT)
Q_PROPERTY(ScriptsModelFilter* scriptsModelFilter READ scriptsModelFilter CONSTANT)
Q_PROPERTY(QString previousScriptLocation READ getPreviousScriptLocation WRITE setPreviousScriptLocation NOTIFY previousScriptLocationChanged)
public:
using ScriptInitializer = std::function<void(ScriptEngine*)>;
@ -72,6 +73,7 @@ signals:
void scriptCountChanged();
void scriptsReloading();
void scriptLoadError(const QString& filename, const QString& error);
void previousScriptLocationChanged();
protected slots:
void onScriptFinished(const QString& fileNameString, ScriptEngine* engine);