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 | 544 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 545 | 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 | 547 | // register various meta-types |
| 558 | 548 | registerMetaTypes(this); |
| @@ -1850,7 +1840,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1291 unmodified lines | ||
| 1850 | 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 | 1844 | if (QThread::currentThread() != thread()) { |
| 1855 | 1845 | #ifdef THREAD_DEBUGGING |
| 1856 | 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 | 1848 | #endif |
| 1859 | 1849 | |
| 1860 | 1850 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| 1861 | − Q_ARG(const EntityItemID&, entityID)); | |
| 1851 | + Q_ARG(const EntityItemID&, entityID), | |
| 1852 | + Q_ARG(bool, shouldRemoveFromMap)); | |
| 1862 | 1853 | return; |
| 1863 | 1854 | } |
| 1864 | 1855 | #ifdef THREAD_DEBUGGING |
| @@ -1873,7 +1864,12 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 8 unmodified lines | ||
| 1873 | 1864 | } else { |
| 1874 | 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 | 1873 | EntityScriptDetails newDetails; |
| 1878 | 1874 | newDetails.status = EntityScriptStatus::UNLOADED; |
| 1879 | 1875 | newDetails.lastModified = QDateTime::currentMSecsSinceEpoch(); |
| @@ -1881,6 +1877,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 1 unmodified line | ||
| 1881 | 1877 | newDetails.scriptText = oldDetails.scriptText; |
| 1882 | 1878 | setEntityScriptDetails(entityID, newDetails); |
| 1883 | 1879 | } |
| 1880 | + | |
| 1884 | 1881 | stopAllTimersForEntityScript(entityID); |
| 1885 | 1882 | { |
| 1886 | 1883 | // FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests |