Fix Godot 4.7 typed array crash: add freed-object filtering in PropertyPool and PerObjectHistory

This commit is contained in:
2026-07-03 16:09:59 -04:00
parent fc2c0236cb
commit 5a1695e2ab
3 changed files with 22 additions and 3 deletions
@@ -11,8 +11,14 @@ func _init(p_history_size: int):
_history_size = p_history_size
func subjects() -> Array[Object]:
# Filter out freed objects — Godot 4.7 stricter typed arrays
# reject invalid references and crash the engine.
var valid := []
for o in _data.keys():
if is_instance_valid(o):
valid.append(o)
var result := [] as Array[Object]
result.assign(_data.keys())
result.assign(valid)
return result
func is_auth(tick: int, subject: Object) -> bool:
+7 -1
View File
@@ -49,8 +49,14 @@ func get_properties_of(subject: Object) -> Array[NodePath]:
return properties
func get_subjects() -> Array[Object]:
# Filter out freed objects — Godot 4.7 stricter typed arrays
# reject invalid references and crash the engine.
var valid := []
for s in _properties_by_subject.keys():
if is_instance_valid(s):
valid.append(s)
var subjects := [] as Array[Object]
subjects.assign(_properties_by_subject.keys())
subjects.assign(valid)
return subjects
func is_empty() -> bool:
+8 -1
View File
@@ -110,7 +110,14 @@ func _on_first_peer_join(_peer_id: int) -> void:
return
_first_client_connected = true
print("[HeadlessServer] First client connected — starting netfox tick loop...")
print("[HeadlessServer] First client connected — letting avatar spawn...")
# Wait TWO frames so PlayerSpawner._handle_new_peer() creates the avatar
# BEFORE NetworkTime starts. The tick loop needs at least one subject.
await get_tree().process_frame
await get_tree().process_frame
print("[HeadlessServer] Starting netfox tick loop with player subjects...")
# Start netfox tick loop now that we have at least one player
if NetworkTime and NetworkTime.has_method("start"):