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