Skip to content

Editor crashes if edited_root_scene is deleted #81320

@hankedan000

Description

@hankedan000

Godot version

4.1.1.stable

System information

Any

Issue description

If the root scene being edited is deleted, then the godot editor will crash. This can happen if a tool script has poor logic and calls queue_free() on the edited root scene.

I think the editor should catch this and prevent the crash from happening. It should log an error to the console letting the developer know that they are doing something wrong in their tool scripts.

I've attached a reproducer project that shows this crash. All it really takes is for a tool script to call the queue_free() on itself, but I made it do so after a short duration. Here's the tool script I made.

@tool
extends Sprite2D

var ttl = 3
@onready var child := $Child

func _process(delta):
	ttl -= delta# decrement time to live
	if ttl <= 0:
		if child:
			print("deleting child")
			child.queue_free()# editor seems to be okay with deleting children
			child = null
			ttl = 3
		else:
			print("deleting self")
			self.queue_free()# this will crash editor!!!

Steps to reproduce

Create a Node2D scene in the editor.
Attach a script to the node.
Paste the following into the script.

@tool
extends Sprite2D

var ttl = 3
@onready var child := $Child

func _process(delta):
	ttl -= delta# decrement time to live
	if ttl <= 0:
		if child:
			print("deleting child")
			child.queue_free()# editor seems to be okay with deleting children
			child = null
			ttl = 3
		else:
			print("deleting self")
			self.queue_free()# this will crash editor!!!

Close the scene and reopen it in the editor.
Wait 6s and the editor should crash.

Minimal reproduction project

QueueFreeCrash_4.1.1.tar.gz

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    For team assessment

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions