Skip to content

Commit ea93ad5

Browse files
committed
Fix memory leak in main.gd fallback timer
- Add fallback_timer class variable to track timer reference - Clean up fallback timer when tutorial completes normally - Clean up fallback timer when check_spawning_status runs - Prevents memory leak from orphaned timer nodes This ensures proper cleanup of the fallback timer used for tutorial completion detection, preventing potential memory leaks.
1 parent ac62cef commit ea93ad5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

scripts/core/main.gd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var game_tutorial: GameTutorial = null
1212
# Error display system
1313
var error_display: ErrorDisplay = null
1414

15+
# Fallback timer for tutorial completion
16+
var fallback_timer: Timer = null
17+
1518
func _ready():
1619
# Setup error display
1720
setup_error_display()
@@ -30,7 +33,7 @@ func _ready():
3033
Logger.info("Signal connection status: %s" % game_tutorial.tutorial_completed.is_connected(_on_tutorial_completed_and_start_spawning), "Main")
3134

3235
# Add a fallback timer to check if spawning should have started
33-
var fallback_timer = Timer.new()
36+
fallback_timer = Timer.new()
3437
fallback_timer.wait_time = 10.0 # 10 seconds
3538
fallback_timer.timeout.connect(_check_spawning_status)
3639
add_child(fallback_timer)
@@ -58,6 +61,11 @@ func _on_tutorial_completed_and_start_spawning():
5861
Logger.info("Tutorial completed, starting enemy spawning", "Main")
5962
spawn_enemy_timer()
6063

64+
# Clean up fallback timer since tutorial completed normally
65+
if fallback_timer:
66+
fallback_timer.queue_free()
67+
fallback_timer = null
68+
6169
# Disconnect the signal to prevent multiple calls
6270
if game_tutorial and game_tutorial.tutorial_completed.is_connected(_on_tutorial_completed_and_start_spawning):
6371
game_tutorial.tutorial_completed.disconnect(_on_tutorial_completed_and_start_spawning)
@@ -81,6 +89,11 @@ func _check_spawning_status():
8189
Logger.info("Tutorial is not active, spawning should have started", "Main")
8290
# Force start spawning if it hasn't started
8391
spawn_enemy_timer()
92+
93+
# Clean up the fallback timer
94+
if fallback_timer:
95+
fallback_timer.queue_free()
96+
fallback_timer = null
8497

8598
func spawn_enemy_timer():
8699
Logger.info("Creating enemy spawn timer", "Main")

0 commit comments

Comments
 (0)