History

handle possibly deleted ScriptEngine in getScriptContents

Brad Hefta-Gaub committed 10 years ago

Commit 71d57291 parent 87078b11 file · +10 −2Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+10−2
@@ -1077,13 +1077,21 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 1076 unmodified lines
1077 qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread ["1077 qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread ["
1078 << QThread::currentThread() << "] expected thread [" << thread() << "]";1078 << QThread::currentThread() << "] expected thread [" << thread() << "]";
1079#endif1079#endif
1080 DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {1080
1081 QPointer<ScriptEngine> theEngine(this);
1082
1083 DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [theEngine, entityID](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
1081#ifdef THREAD_DEBUGGING1084#ifdef THREAD_DEBUGGING
1082 qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread ["1085 qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread ["
1083 << QThread::currentThread() << "] expected thread [" << thread() << "]";1086 << QThread::currentThread() << "] expected thread [" << thread() << "]";
1084#endif1087#endif
1085 1088
1086 this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success);1089 if (!theEngine.isNull()) {
1090 qDebug() << "ScriptCache::getScriptContents() returned ScriptEngine still active calling ... entityScriptContentAvailable()";
1091 theEngine->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success);
1092 } else {
1093 qDebug() << "ScriptCache::getScriptContents() returned after our ScriptEngine was deleted...";
1094 }
1087 }, forceRedownload);1095 }, forceRedownload);
1088}1096}
1089 1097