Fix 2: Guard against null archSpirit in get_unit_by_id and _apply_delta

GDScript dict.get(key, fallback) only returns the fallback when the key
is absent. When a player disconnects the server sets archSpirit to null
(key present, value null), so .get("archSpirit", {}) returns null and
the next .get("instanceId") call crashes with 'Nonexistent function
get in base Nil'.

- get_unit_by_id (~line 276): replace typed Dictionary assignment with
  Variant + 'is Dictionary' guard (same pattern already used correctly
  in get_all_enemy_units)
- _apply_delta §7 (~line 633): replace typed Dictionary assignment with
  Variant + null/type guard before casting; null or non-Dictionary
  triggers request_sync() the same as an empty baseline would

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:
dingo
2026-05-20 19:57:59 -04:00
co-authored by Claude Happy
parent 14a467dc69
commit e7bf25759f
+9 -4
View File
@@ -273,9 +273,10 @@ func get_unit_by_id(instance_id: String) -> Dictionary:
for u: Dictionary in p.get("field", []):
if u.get("instanceId", "") == instance_id:
return u
var arch: Dictionary = p.get("archSpirit", {})
if arch.get("instanceId", "") == instance_id:
return arch
var arch_val: Variant = p.get("archSpirit")
if arch_val is Dictionary and not (arch_val as Dictionary).is_empty():
if (arch_val as Dictionary).get("instanceId", "") == instance_id:
return arch_val
return {}
@@ -630,7 +631,11 @@ func _apply_delta(delta: Dictionary) -> void:
var arch_delta := arch_update.get("delta") as Dictionary
if arch_delta.is_empty():
continue
var arch: Dictionary = player.get("archSpirit", {})
var arch_val: Variant = player.get("archSpirit")
if arch_val == null or not (arch_val is Dictionary):
request_sync()
continue
var arch := arch_val as Dictionary
if arch.is_empty():
# Missing baseline (likely first sight of this arch). Ask for full sync.
request_sync()