diff --git a/Client/origin-client/autoloads/ModelCache.gd b/Client/origin-client/autoloads/ModelCache.gd index f68b4f8..9fe02eb 100644 --- a/Client/origin-client/autoloads/ModelCache.gd +++ b/Client/origin-client/autoloads/ModelCache.gd @@ -92,6 +92,31 @@ func evict(url: String, etag: String = "") -> void: DirAccess.remove_absolute(disk) +## Drop all in-memory PackedScene references and flush the pending queue. +## Sets _shutting_down first so any in-flight HTTP callbacks that complete +## after scene teardown return null instead of firing into freed nodes. +## Disk cache (.bin files) is intentionally left intact so subsequent +## sessions still benefit from skipping re-downloads. +func evict_all() -> void: + _shutting_down = true + + # Flush all queued callbacks with null so callers don't hang. + for key: String in _pending: + for cb: Callable in _pending[key]: + cb.call(null) + _pending.clear() + + _mem.clear() + _job_queue.clear() + # _active_jobs is intentionally left alone; in-flight HTTPRequest nodes own + # those slots and will call _finish_job() when complete (draining an empty queue). + + # Re-arm immediately so load_model() works for the next game. + _shutting_down = false + + if OS.is_debug_build(): + print("ModelCache: evict_all complete") + ## Request a model by CDN URL. ## callback(node: Node3D) is called on the main thread; node may be null. ## If the same URL+ETag is already downloading, callbacks are queued and all diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 715bbfe..1d16f5b 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -377,6 +377,7 @@ func _exit_tree() -> void: _reset_unit_hover_glow() Chat.set_bubble_host(null) Chat.release_bubble_visibility(self) + ModelCache.evict_all() # ── State → scene orchestration ───────────────────────────────────────────────