godot icon indicating copy to clipboard operation
godot copied to clipboard

Printing in the same frame the window closes gives no output

Open pedrotrschneider opened this issue 1 year ago • 6 comments

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

  1. Create a new scene with a root node of type Node;
  2. 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()
  1. Press play, then press the ESCAPE key;
  2. Check the output console and verify that nothing got printed;
  3. 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()
  1. Press play, then press the ESCAPE key;
  2. Check the output console and verify that "I'm exiting the tree" was printed correctly.

Minimal reproduction project (MRP)

print-on-close-test.zip

pedrotrschneider avatar Apr 14 '24 15:04 pedrotrschneider

This might be related to the debugger-process disconnecting from the game-process before it receives the print message.

Sauermann avatar Apr 15 '24 17:04 Sauermann

This has been reported elsewhere I'm pretty sure, can't find rn

AThousandShips avatar Apr 15 '24 17:04 AThousandShips

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 avatar Apr 17 '24 13:04 berarma

@berarma weird, I had this issue specifically in 4.2.2 rc3. Did you try the project I provided?

pedrotrschneider avatar Apr 17 '24 14:04 pedrotrschneider

@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.

berarma avatar Apr 17 '24 15:04 berarma

I also have this problem, in Godot v4.3.stable.official [77dcf97d8] @pedrotrschneider thanks for the workaround using a timer!

ChaoticByte avatar Oct 01 '24 20:10 ChaoticByte