Skip to content

Push an error after awaiting a signal and unreference/free the object. #107859

Open
@Daylily-Zeleen

Description

@Daylily-Zeleen

Tested versions

v4.5.beta.custom_build [8a27aca]

System information

Windows 10 - v4.5.beta.custom_build [8a27aca]

Issue description

Await a signal and unreference the object will push an error like below:

E 0:00:08:111   test.gd:13 @ _ready(): Object '<Object#-9223372002830580334>' was freed or unreferenced while a signal is being emitted from it. Try connecting to the signal using 'CONNECT_DEFERRED' flag, or use queue_free() to free the object (if this object is a Node) to avoid this error and potential crashes.
  <C++ 源文件>     core\object\object.cpp:2272 @ Object::~Object()
  <栈追踪>         test.gd:13 @ _ready()

Steps to reproduce

Attach this script to a node and just run the scene.

extends Node2D

class Test:
	signal test(a: int)

	func _init() -> void:
		Engine.get_main_loop().create_timer(0.5).timeout.connect(test.emit.bind(10))


func _ready() -> void:
	var t := Test.new()
	var res := (await t.test) as int
	t = null
	print("Test: ", res)

Minimal reproduction project (MRP)

MRP.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions