Printing in the same frame the window closes gives no output
Tested versions
- Tested in: 4.2.2 rc2 and 4.2.2 rc3
System information
Godot v4.2.2.rc3 - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 6GB Laptop GPU (NVIDIA; 31.0.15.4601) - 13th Gen Intel(R) Core(TM) i5-13450HX (16 Threads)
Issue description
If I try to print anything on the same frame the game window closes in the editor, nothing gets printed. For example, if I run a scene with the following script attached, I would expect to see "I'm exiting the tree" in the output console after pressing ESCAPE:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
print("I'm exiting the tree")
get_tree().quit()
However, upon testing, the output console is empty. If I add an await get_tree().create_timer(0.1).timeout statement after the print line, however, it prints to the output as expected:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
print("I'm exiting the tree")
await get_tree().create_timer(0.1).timeout
get_tree().quit()
It also works if I add a breakpoint in place of the await get_tree().create_timer(0.1).timeout, so it seems that Godot just doesn't like printing stuff in the same frame the window closes.
I have also tested using the _exit_tree function and the behaviour is the same. The following code does not print anything when I press ESCAPE:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
func _exit_tree() -> void:
print("I'm exiting the tree")
But if I add a breakpoint, it works correctly:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
func _exit_tree() -> void:
print("I'm exiting the tree")
breakpoint
Steps to reproduce
- Create a new scene with a root node of type
Node; - Attach the following script to that node:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
print("I'm exiting the tree")
get_tree().quit()
- Press play, then press the ESCAPE key;
- Check the output console and verify that nothing got printed;
- Change the script to the following:
extends Node
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
print("I'm exiting the tree")
await get_tree().create_timer(0.1).timeout
get_tree().quit()
- Press play, then press the ESCAPE key;
- Check the output console and verify that "I'm exiting the tree" was printed correctly.
Minimal reproduction project (MRP)
This might be related to the debugger-process disconnecting from the game-process before it receives the print message.
This has been reported elsewhere I'm pretty sure, can't find rn
Yesterday I was having this issue with Godot 4.2.1, now I can't reproduce it with 4.2.2-rc3.
Maybe related: #87493
@berarma weird, I had this issue specifically in 4.2.2 rc3. Did you try the project I provided?
@berarma weird, I had this issue specifically in 4.2.2 rc3. Did you try the project I provided?
No, it was with another project. Maybe something I changed from yesterday to now. I should have tested again with 4.2.1 but I couldn't do more tests today.
I also have this problem, in Godot v4.3.stable.official [77dcf97d8] @pedrotrschneider thanks for the workaround using a timer!