Skip to content

Commit 3dc4e5c

Browse files
authored
fix: Disconnect signals on exiting tree (#341)
Disconnects signals on leaving the scene tree and reconnects them when entering. Should avoid any `!is_inside_tree()` errors.
1 parent 2167981 commit 3dc4e5c

7 files changed

Lines changed: 48 additions & 14 deletions

File tree

addons/netfox.extras/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.extras"
44
description="Game-specific utilities for Netfox"
55
author="Tamas Galffy"
6-
version="1.14.1"
6+
version="1.14.2"
77
script="netfox-extras.gd"

addons/netfox.internals/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.internals"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy"
6-
version="1.14.1"
6+
version="1.14.2"
77
script="plugin.gd"

addons/netfox.noray/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.noray"
44
description="Bulletproof your connectivity with noray integration for netfox"
55
author="Tamas Galffy"
6-
version="1.14.1"
6+
version="1.14.2"
77
script="netfox-noray.gd"

addons/netfox/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy"
6-
version="1.14.1"
6+
version="1.14.2"
77
script="netfox.gd"

addons/netfox/rollback/rollback-synchronizer.gd

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,7 @@ func process_authority():
131131
_auth_input_property_entries.push_back(property_entry)
132132
_record_input_property_entries.push_back(property_entry)
133133

134-
func _ready():
135-
if not NetworkTime.is_initial_sync_done():
136-
# Wait for time sync to complete
137-
await NetworkTime.after_sync
138-
process_settings.call_deferred()
139-
134+
func _connect_signals():
140135
NetworkTime.before_tick.connect(_before_tick)
141136
NetworkTime.after_tick.connect(_after_tick)
142137
NetworkRollback.before_loop.connect(_before_loop)
@@ -145,6 +140,26 @@ func _ready():
145140
NetworkRollback.on_record_tick.connect(_record_tick)
146141
NetworkRollback.after_loop.connect(_after_loop)
147142

143+
func _disconnect_signals():
144+
NetworkTime.before_tick.disconnect(_before_tick)
145+
NetworkTime.after_tick.disconnect(_after_tick)
146+
NetworkRollback.before_loop.disconnect(_before_loop)
147+
NetworkRollback.on_prepare_tick.disconnect(_prepare_tick)
148+
NetworkRollback.on_process_tick.disconnect(_process_tick)
149+
NetworkRollback.on_record_tick.disconnect(_record_tick)
150+
NetworkRollback.after_loop.disconnect(_after_loop)
151+
152+
func _enter_tree():
153+
if not NetworkTime.is_initial_sync_done():
154+
# Wait for time sync to complete
155+
await NetworkTime.after_sync
156+
_connect_signals.call_deferred()
157+
process_settings.call_deferred()
158+
159+
func _exit_tree():
160+
_is_initialized = false
161+
_disconnect_signals()
162+
148163
func _before_loop():
149164
if _auth_input_property_entries.is_empty():
150165
# We don't have any inputs we own, simulate from earliest we've received

addons/netfox/state-synchronizer.gd

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ func process_settings():
2323
var property_entry = _property_cache.get_entry(property)
2424
_property_entries.push_back(property_entry)
2525

26-
func _ready():
27-
process_settings()
26+
func _connect_signals():
2827
NetworkTime.after_tick.connect(_after_tick)
2928

29+
func _disconnect_signals():
30+
NetworkTime.after_tick.disconnect(_after_tick)
31+
32+
func _enter_tree():
33+
_connect_signals.call_deferred()
34+
process_settings.call_deferred()
35+
36+
func _exit_tree():
37+
_disconnect_signals()
38+
3039
func _after_tick(_dt, tick):
3140
if is_multiplayer_authority():
3241
# Submit snapshot

addons/netfox/tick-interpolator.gd

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,26 @@ func teleport():
5151
_state_from = PropertySnapshot.extract(_property_entries)
5252
_state_to = _state_from
5353

54-
func _ready():
55-
process_settings()
54+
func _connect_signals():
5655
NetworkTime.before_tick_loop.connect(_before_tick_loop)
5756
NetworkTime.after_tick_loop.connect(_after_tick_loop)
5857

58+
func _disconnect_signals():
59+
NetworkTime.before_tick_loop.disconnect(_before_tick_loop)
60+
NetworkTime.after_tick_loop.disconnect(_after_tick_loop)
61+
62+
func _enter_tree():
63+
process_settings()
64+
_connect_signals.call_deferred()
65+
5966
# Wait a frame for any initial setup before recording first state
6067
if record_first_state:
6168
await get_tree().process_frame
6269
teleport()
6370

71+
func _exit_tree():
72+
_disconnect_signals()
73+
6474
func _process(_delta):
6575
_interpolate(_state_from, _state_to, NetworkTime.tick_factor)
6676

0 commit comments

Comments
 (0)