History

Fix entity script destruction

* Unload scripts that are auto-refreshing before restarting them. (#1697) * Refactors `entityScriptChanging` to account for old and new URLs, was previously always setting them both to `""` and failing. (#2187) * Cleaned up `EntityTreeRenderer::checkAndCallPreload` to be less confusing lol

Ada committed 6 months ago

Commit 1b12e111 parent 144bb539 files · +61 −62Browse files

Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 9 files). Show all

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+4−4
@@ -2658,11 +2658,10 @@ void ScriptManager::refreshFileScript(const EntityItemID& entityID, const QStrin · 2657 unmodified lines
26582658 return;
26592659 }
26602660
2661− static bool recurseGuard = false;
2662− if (recurseGuard) {
2661+ if (_refreshRecurseGuard) {
26632662 return;
26642663 }
2665− recurseGuard = true;
2664+ _refreshRecurseGuard = true;
26662665
26672666 EntityScriptDetails details;
26682667 {
@@ -2675,10 +2674,11 @@ void ScriptManager::refreshFileScript(const EntityItemID& entityID, const QStrin · 6 unmodified lines
26752674 auto lastModified = QFileInfo(filePath).lastModified().toMSecsSinceEpoch();
26762675 if (lastModified > details.lastModified) {
26772676 scriptInfoMessage("Reloading modified script " + details.scriptText, filePath, -1);
2677+ unloadEntityScript(entityID, details.scriptText, true);
26782678 loadEntityScript(entityID, details.scriptText, true);
26792679 }
26802680 }
2681− recurseGuard = false;
2681+ _refreshRecurseGuard = false;
26822682 }
26832683
26842684 // Execute operation in the appropriate context for (the possibly empty) entityID.