Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -1620,8 +1620,14 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 1619 unmodified lines | ||
| 1620 | 1620 | setEntityScriptDetails(entityID, newDetails); |
| 1621 | 1621 | |
| 1622 | 1622 | auto scriptCache = DependencyManager::get<ScriptCache>(); |
| 1623 | + // note: see EntityTreeRenderer.cpp for shared pointer lifecycle management | |
| 1624 | + QWeakPointer<ScriptEngine> weakRef(sharedFromThis()); | |
| 1623 | 1625 | scriptCache->getScriptContents(entityScript, |
| 1624 | − [this, entityScript, entityID](const QString& url, const QString& contents, bool isURL, bool success, const QString& status) { | |
| 1626 | + [this, weakRef, entityScript, entityID](const QString& url, const QString& contents, bool isURL, bool success, const QString& status) { | |
| 1627 | + if (!weakRef) { | |
| 1628 | + qCWarning(scriptengine) << "loadEntityScript.contentAvailable -- ScriptEngine was deleted during getScriptContents!!"; | |
| 1629 | + return; | |
| 1630 | + } | |
| 1625 | 1631 | if (isStopping()) { |
| 1626 | 1632 | #ifdef DEBUG_ENTITY_STATES |
| 1627 | 1633 | qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- stopping"; |