Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 25 files). Show all
Unified · Split
| @@ -543,16 +543,6 @@ void ScriptEngine::init() { · 542 unmodified lines | |||
| 543 | 543 | ||
| 544 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | 544 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 545 | entityScriptingInterface->init(); | 545 | entityScriptingInterface->init(); |
| 546 | connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, this, [this](const EntityItemID& entityID) { | ||
| 547 | if (_entityScripts.contains(entityID)) { | ||
| 548 | if (isEntityScriptRunning(entityID)) { | ||
| 549 | qCWarning(scriptengine) << "deletingEntity while entity script is still running!" << entityID; | ||
| 550 | } | ||
| 551 | _entityScripts.remove(entityID); | ||
| 552 | emit entityScriptDetailsUpdated(); | ||
| 553 | } | ||
| 554 | }); | ||
| 555 | |||
| 556 | 546 | ||
| 557 | // register various meta-types | 547 | // register various meta-types |
| 558 | registerMetaTypes(this); | 548 | registerMetaTypes(this); |
| @@ -1850,7 +1840,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1291 unmodified lines | |||
| 1850 | processDeferredEntityLoads(entityScript, entityID); | 1840 | processDeferredEntityLoads(entityScript, entityID); |
| 1851 | } | 1841 | } |
| 1852 | 1842 | ||
| 1853 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { | 1843 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap) { |
| 1854 | if (QThread::currentThread() != thread()) { | 1844 | if (QThread::currentThread() != thread()) { |
| 1855 | #ifdef THREAD_DEBUGGING | 1845 | #ifdef THREAD_DEBUGGING |
| 1856 | qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1846 | qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| @@ -1858,7 +1848,8 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 1 unmodified line | |||
| 1858 | #endif | 1848 | #endif |
| 1859 | 1849 | ||
| 1860 | QMetaObject::invokeMethod(this, "unloadEntityScript", | 1850 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| 1861 | Q_ARG(const EntityItemID&, entityID)); | 1851 | Q_ARG(const EntityItemID&, entityID), |
| 1852 | Q_ARG(bool, shouldRemoveFromMap)); | ||
| 1862 | return; | 1853 | return; |
| 1863 | } | 1854 | } |
| 1864 | #ifdef THREAD_DEBUGGING | 1855 | #ifdef THREAD_DEBUGGING |
| @@ -1873,7 +1864,12 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 8 unmodified lines | |||
| 1873 | } else { | 1864 | } else { |
| 1874 | qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status; | 1865 | qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status; |
| 1875 | } | 1866 | } |
| 1876 | if (oldDetails.status != EntityScriptStatus::UNLOADED) { | 1867 | |
| 1868 | if (shouldRemoveFromMap) { | ||
| 1869 | // this was a deleted entity, we've been asked to remove it from the map | ||
| 1870 | _entityScripts.remove(entityID); | ||
| 1871 | emit entityScriptDetailsUpdated(); | ||
| 1872 | } else if (oldDetails.status != EntityScriptStatus::UNLOADED) { | ||
| 1877 | EntityScriptDetails newDetails; | 1873 | EntityScriptDetails newDetails; |
| 1878 | newDetails.status = EntityScriptStatus::UNLOADED; | 1874 | newDetails.status = EntityScriptStatus::UNLOADED; |
| 1879 | newDetails.lastModified = QDateTime::currentMSecsSinceEpoch(); | 1875 | newDetails.lastModified = QDateTime::currentMSecsSinceEpoch(); |
| @@ -1881,6 +1877,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 1 unmodified line | |||
| 1881 | newDetails.scriptText = oldDetails.scriptText; | 1877 | newDetails.scriptText = oldDetails.scriptText; |
| 1882 | setEntityScriptDetails(entityID, newDetails); | 1878 | setEntityScriptDetails(entityID, newDetails); |
| 1883 | } | 1879 | } |
| 1880 | |||
| 1884 | stopAllTimersForEntityScript(entityID); | 1881 | stopAllTimersForEntityScript(entityID); |
| 1885 | { | 1882 | { |
| 1886 | // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests | 1883 | // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests |