Skip to content

Engine crash when removing node in specific situation #77480

@KoBeWi

Description

@KoBeWi

Godot version

3.5.2

System information

Windows 10 x64

Issue description

I found out that you can delete a node in a specific situation that should be blocked. This causes invalid node to stay in the scene tree, which is basically a ticking bomb:
image
When the parent node is being freed, the broken node causes hard crash with very obscure stack trace (assuming you use C++ debugger, otherwise there is no error log). This can happen e.g. when changing scenes and also leads to random bugs like null during get_children() iteration.

The issue does not happen in 4.x, as this situation is handled and results in an error.

Steps to reproduce

  1. Attach this script to a node
extends Node

func _ready() -> void:
	var ui = Node.new()
	add_child(ui)
	
	var menu = Node.new()
	ui.add_child(menu)
	
	var interface = Node.new()
	ui.add_child(interface)
	interface.connect("tree_exiting", menu.get_parent(), "remove_child", [menu])
	
	get_tree().create_timer(0.5).connect("timeout", interface, "queue_free") # invalid node here (and cow_data error)
	get_tree().create_timer(1).connect("timeout", self, "queue_free") # crash
  1. Run

Minimal reproduction project

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions