diff --git a/world.gd b/world.gd index 5275304..9e1cc3d 100644 --- a/world.gd +++ b/world.gd @@ -91,6 +91,7 @@ func update_generation_ui() -> void: # Conway Specific # func start_conway() -> void: + clear_world() generate_world() generation = 1 @@ -173,6 +174,15 @@ func toggle_pause() -> void: else: generation_timer.start() +## Loop over cell_ids and free the resource in the RenderingServer +## Clear cell_ids and cell_states +func clear_world() -> void: + for row in cell_ids: + for id in row: + RenderingServer.free_rid(id) + cell_ids = [] + cell_states = [] + ## Create the cell using the rendering server ## This is only performed on initial world generation func create_cell(pos: Vector2, visible_cell: bool = true) -> RID: @@ -237,3 +247,7 @@ func _on_start_paused_button_toggled(button_pressed: bool) -> void: func _on_world_seed_generate_pressed() -> void: generation_seed.text = str(randi()) + + +func _exit_tree() -> void: + clear_world()