Fix 5: iOS Safari scoped asset loading and memory management
- New Platform.gd autoload: is_ios_safari() detects iPhone/iPad Safari via JavaScriptBridge UA check (no Chrome/CriOS), gating all iOS memory paths - ModelCache.release_model(url, etag): evicts a model from in-memory cache on iOS Safari when a unit leaves the board; no-op on other platforms so disk cache is always preserved for fast reload - unit_mesh_builder: stores resolved model URL+ETag per unit (_unit_model_urls, _unit_model_etags); calls ModelCache.release_model in the to_remove loop so PackedScene refs are freed as soon as the unit is pooled or freed - ContentCache.get_model_url_for_definition: stub for looking up a card's Model3D CDN URL without a loaded unit dict (foundation for future eviction paths) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -33,6 +33,8 @@ var turn_glow_rings: Dictionary = {} # iid → MeshInstance3D
|
||||
var materialize_until: Dictionary = {} # iid → Time.get_ticks_msec deadline
|
||||
var unit_owner_ids: Dictionary = {} # iid → accountId
|
||||
var _unit_load_gen: Dictionary = {} # iid → int (incremented each model-load start; stale callbacks bail out)
|
||||
var _unit_model_urls: Dictionary = {} # iid → String (CDN URL used when the model was loaded)
|
||||
var _unit_model_etags: Dictionary = {} # iid → String (ETag used when the model was loaded)
|
||||
|
||||
var _active_tweens: Array[Tween] = [] # shader tweens tracked for kill-on-rebuild
|
||||
|
||||
@@ -188,6 +190,10 @@ func rebuild_units(state: Dictionary) -> void:
|
||||
, CONNECT_ONE_SHOT)
|
||||
else:
|
||||
_pool_unit(body, card_type)
|
||||
# Release the 3D model from memory (no-op on non-iOS; frees heap on iOS Safari).
|
||||
ModelCache.release_model(
|
||||
str(_unit_model_urls.get(iid, "")),
|
||||
str(_unit_model_etags.get(iid, "")))
|
||||
unit_bodies.erase(iid)
|
||||
unit_meshes.erase(iid)
|
||||
anim_players.erase(iid)
|
||||
@@ -203,6 +209,8 @@ func rebuild_units(state: Dictionary) -> void:
|
||||
turn_glow_rings.erase(iid)
|
||||
materialize_until.erase(iid)
|
||||
unit_owner_ids.erase(iid)
|
||||
_unit_model_urls.erase(iid)
|
||||
_unit_model_etags.erase(iid)
|
||||
|
||||
# 3. Add units not yet present (newly played, or first render after connect).
|
||||
for iid: String in desired:
|
||||
@@ -357,6 +365,10 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false,
|
||||
model_base_angles[iid] = base_angle
|
||||
needs_face_rot[iid] = needs_face_rotation
|
||||
|
||||
# Store the resolved URL+ETag so we can release the cached model on removal.
|
||||
_unit_model_urls[iid] = model_url
|
||||
_unit_model_etags[iid] = model_etag
|
||||
|
||||
var body_ref: Variant = weakref(body)
|
||||
# Stale-callback guard: bump generation so any previous in-flight load
|
||||
# for this iid will bail out when it fires.
|
||||
|
||||
Reference in New Issue
Block a user