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
10771077 qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread ["
10781078 << QThread::currentThread() << "] expected thread [" << thread() << "]";
10791079 #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) {
10811084 #ifdef THREAD_DEBUGGING
10821085 qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread ["
10831086 << QThread::currentThread() << "] expected thread [" << thread() << "]";
10841087 #endif
10851088
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+ }
10871095 }, forceRedownload);
10881096 }
10891097