Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 15 files). Show all
Unified · Split
| @@ -583,16 +583,6 @@ void ScriptEngine::init() { · 582 unmodified lines | |||
| 583 | 583 | ||
| 584 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 584 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 585 | entityScriptingInterface->init(); | 585 | entityScriptingInterface->init(); |
| 586 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, this, [this](const EntityItemID& entityID) { | ||
| 587 | if (_entityScripts.contains(entityID)) { | ||
| 588 | if (isEntityScriptRunning(entityID) && !isStopping()) { | ||
| 589 | qCWarning(scriptengine) << "deletingEntity while entity script is still running" << entityID; | ||
| 590 | } | ||
| 591 | _entityScripts.remove(entityID); | ||
| 592 | emit entityScriptDetailsUpdated(); | ||
| 593 | } | ||
| 594 | }); | ||
| 595 | |||
| 596 | 586 | ||
| 597 | // register various meta-types | 587 | // register various meta-types |
| 598 | registerMetaTypes(this); | 588 | registerMetaTypes(this); |
| @@ -2291,7 +2281,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1692 unmodified lines | |||
| 2291 | processDeferredEntityLoads(entityScript, entityID); | 2281 | processDeferredEntityLoads(entityScript, entityID); |
| 2292 | } | 2282 | } |
| 2293 | 2283 | ||
| 2294 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { | 2284 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap) { |
| 2295 | if (QThread::currentThread() != thread()) { | 2285 | if (QThread::currentThread() != thread()) { |
| 2296 | #ifdef THREAD_DEBUGGING | 2286 | #ifdef THREAD_DEBUGGING |
| 2297 | qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 2287 | qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| @@ -2299,7 +2289,8 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 1 unmodified line | |||
| 2299 | #endif | 2289 | #endif |
| 2300 | 2290 | ||
| 2301 | QMetaObject::invokeMethod(this, "unloadEntityScript", | 2291 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| 2302 | Q_ARG(const EntityItemID&, entityID)); | 2292 | Q_ARG(const EntityItemID&, entityID), |
| 2293 | Q_ARG(bool, shouldRemoveFromMap)); | ||
| 2303 | return; | 2294 | return; |
| 2304 | } | 2295 | } |
| 2305 | #ifdef THREAD_DEBUGGING | 2296 | #ifdef THREAD_DEBUGGING |
| @@ -2317,7 +2308,11 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 11 unmodified lines | |||
| 2317 | qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status; | 2308 | qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status; |
| 2318 | } | 2309 | } |
| 2319 | #endif | 2310 | #endif |
| 2320 | if (oldDetails.status != EntityScriptStatus::UNLOADED) { | 2311 | if (shouldRemoveFromMap) { |
| 2312 | // this was a deleted entity, we've been asked to remove it from the map | ||
| 2313 | _entityScripts.remove(entityID); | ||
| 2314 | emit entityScriptDetailsUpdated(); | ||
| 2315 | } else if (oldDetails.status != EntityScriptStatus::UNLOADED) { | ||
| 2321 | EntityScriptDetails newDetails; | 2316 | EntityScriptDetails newDetails; |
| 2322 | newDetails.status = EntityScriptStatus::UNLOADED; | 2317 | newDetails.status = EntityScriptStatus::UNLOADED; |
| 2323 | newDetails.lastModified = QDateTime::currentMSecsSinceEpoch(); | 2318 | newDetails.lastModified = QDateTime::currentMSecsSinceEpoch(); |
| @@ -2325,6 +2320,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 1 unmodified line | |||
| 2325 | newDetails.scriptText = oldDetails.scriptText; | 2320 | newDetails.scriptText = oldDetails.scriptText; |
| 2326 | setEntityScriptDetails(entityID, newDetails); | 2321 | setEntityScriptDetails(entityID, newDetails); |
| 2327 | } | 2322 | } |
| 2323 | |||
| 2328 | stopAllTimersForEntityScript(entityID); | 2324 | stopAllTimersForEntityScript(entityID); |
| 2329 | { | 2325 | { |
| 2330 | // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests | 2326 | // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests |