mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-04 02:40:43 +02:00
Merge pull request #9879 from birarda/bug/no-unload
make sure deleted entities are unloaded first
This commit is contained in:
commit
a69cf76d06
4 changed files with 14 additions and 17 deletions
|
@ -455,13 +455,13 @@ void EntityScriptServer::addingEntity(const EntityItemID& entityID) {
|
||||||
|
|
||||||
void EntityScriptServer::deletingEntity(const EntityItemID& entityID) {
|
void EntityScriptServer::deletingEntity(const EntityItemID& entityID) {
|
||||||
if (_entityViewer.getTree() && !_shuttingDown && _entitiesScriptEngine) {
|
if (_entityViewer.getTree() && !_shuttingDown && _entitiesScriptEngine) {
|
||||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
_entitiesScriptEngine->unloadEntityScript(entityID, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID, const bool reload) {
|
void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID, const bool reload) {
|
||||||
if (_entityViewer.getTree() && !_shuttingDown) {
|
if (_entityViewer.getTree() && !_shuttingDown) {
|
||||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
_entitiesScriptEngine->unloadEntityScript(entityID, true);
|
||||||
checkAndCallPreload(entityID, reload);
|
checkAndCallPreload(entityID, reload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -940,7 +940,7 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event) {
|
||||||
|
|
||||||
void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
|
void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
|
||||||
if (_tree && !_shuttingDown && _entitiesScriptEngine) {
|
if (_tree && !_shuttingDown && _entitiesScriptEngine) {
|
||||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
_entitiesScriptEngine->unloadEntityScript(entityID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
forceRecheckEntities(); // reset our state to force checking our inside/outsideness of entities
|
forceRecheckEntities(); // reset our state to force checking our inside/outsideness of entities
|
||||||
|
|
|
@ -541,16 +541,6 @@ void ScriptEngine::init() {
|
||||||
|
|
||||||
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||||
entityScriptingInterface->init();
|
entityScriptingInterface->init();
|
||||||
connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, this, [this](const EntityItemID& entityID) {
|
|
||||||
if (_entityScripts.contains(entityID)) {
|
|
||||||
if (isEntityScriptRunning(entityID)) {
|
|
||||||
qCWarning(scriptengine) << "deletingEntity while entity script is still running!" << entityID;
|
|
||||||
}
|
|
||||||
_entityScripts.remove(entityID);
|
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// register various meta-types
|
// register various meta-types
|
||||||
registerMetaTypes(this);
|
registerMetaTypes(this);
|
||||||
|
@ -1844,7 +1834,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
processDeferredEntityLoads(entityScript, entityID);
|
processDeferredEntityLoads(entityScript, entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) {
|
void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
#ifdef THREAD_DEBUGGING
|
#ifdef THREAD_DEBUGGING
|
||||||
qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
|
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) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "unloadEntityScript",
|
QMetaObject::invokeMethod(this, "unloadEntityScript",
|
||||||
Q_ARG(const EntityItemID&, entityID));
|
Q_ARG(const EntityItemID&, entityID),
|
||||||
|
Q_ARG(bool, shouldRemoveFromMap));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef THREAD_DEBUGGING
|
#ifdef THREAD_DEBUGGING
|
||||||
|
@ -1867,7 +1858,12 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) {
|
||||||
} else {
|
} else {
|
||||||
qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status;
|
qCDebug(scriptengine) << "unload called while !running" << entityID << oldDetails.status;
|
||||||
}
|
}
|
||||||
if (oldDetails.status != EntityScriptStatus::UNLOADED) {
|
|
||||||
|
if (shouldRemoveFromMap) {
|
||||||
|
// this was a deleted entity, we've been asked to remove it from the map
|
||||||
|
_entityScripts.remove(entityID);
|
||||||
|
emit entityScriptDetailsUpdated();
|
||||||
|
} else if (oldDetails.status != EntityScriptStatus::UNLOADED) {
|
||||||
EntityScriptDetails newDetails;
|
EntityScriptDetails newDetails;
|
||||||
newDetails.status = EntityScriptStatus::UNLOADED;
|
newDetails.status = EntityScriptStatus::UNLOADED;
|
||||||
newDetails.lastModified = QDateTime::currentMSecsSinceEpoch();
|
newDetails.lastModified = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
@ -1875,6 +1871,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) {
|
||||||
newDetails.scriptText = oldDetails.scriptText;
|
newDetails.scriptText = oldDetails.scriptText;
|
||||||
setEntityScriptDetails(entityID, newDetails);
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAllTimersForEntityScript(entityID);
|
stopAllTimersForEntityScript(entityID);
|
||||||
{
|
{
|
||||||
// FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests
|
// FIXME: shouldn't have to do this here, but currently something seems to be firing unloads moments after firing initial load requests
|
||||||
|
|
|
@ -171,7 +171,7 @@ public:
|
||||||
return _entityScripts.contains(entityID) && _entityScripts[entityID].status == EntityScriptStatus::RUNNING;
|
return _entityScripts.contains(entityID) && _entityScripts[entityID].status == EntityScriptStatus::RUNNING;
|
||||||
}
|
}
|
||||||
Q_INVOKABLE void loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload);
|
Q_INVOKABLE void loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload);
|
||||||
Q_INVOKABLE void unloadEntityScript(const EntityItemID& entityID); // will call unload method
|
Q_INVOKABLE void unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap = false); // will call unload method
|
||||||
Q_INVOKABLE void unloadAllEntityScripts();
|
Q_INVOKABLE void unloadAllEntityScripts();
|
||||||
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName,
|
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName,
|
||||||
const QStringList& params = QStringList()) override;
|
const QStringList& params = QStringList()) override;
|
||||||
|
|
Loading…
Reference in a new issue