godot: Windows release export crashes on scene change

Godot version

4.0.1.stable

System information

Windows 11, Ryzen 3700U Vega 10 iGPU

Issue description

I’m having a lot a problems with the release export of my game on Windows. Running the game from the editor or exporting it as debug doesn’t present the issue.

One of the problems seems to be already tracked https://github.com/godotengine/godot/issues/70910, but after removing some of the objects in a GridContainer I’m still getting crashes (not always) on scene change. I’ve enabled file logs and only sometime I get the following lines reported in the log; other times no error is reported.

USER ERROR: Condition "!canvas_item" is true.
   at: canvas_item_clear (servers/rendering/renderer_canvas_cull.cpp:1642)

I’ve not tried to reproduce the issue in a minimal project but I can try if it’s necessary.

Steps to reproduce

  • create various scenes with many UI elements and containers
  • do a release export of the game (for Windows, not sure if the same happens on Linux)
  • run the game and switch between such scenes
  • randomly, but typically after 4-6 scene changes the game crashes

Minimal reproduction project

N/A

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I continue to see reports about this in the Godot help channels so adding a quick workaround here so people can see it when linked this issue:

Having a node that manages scenes for you instead of using the change scene functions seems to be an effective workaround.

Add a signal you can access from anywhere. If you don’t already have an autoload you can add a new script such as events.gd with the following:

extends Node

signal change_scene(path_to_scene)

and add is as an autoload called Events.

Make a new scene with a Node as a base called SceneManager. Add your existing Main Scene as a child of the SceneManagerand make SceneManager your new Main Scene. Add a script the the SceneManager with the following:

extends Node

func _ready():
	Events.change_scene.connect(_change_scene)


func _change_scene(path_to_scene):
	for child in get_children():
		remove_child(child) # Crashes without explicitly removing from the scene.
		child.queue_free()

	var new_scene = load(path_to_scene).instantiate()
	add_child(new_scene)

Then whenever you need to change scenes you can just use the following code:

Events.change_scene.emit("res://path/to/new/scene.tscn")

@Benardus Yes, that is correct.

As mentioned in the above comment, the fix is only in 4.2.dev currently. It hasn’t been cherry-picked to 4.1.x yet, but this is planned as per the cherrypick:4.1 label on https://github.com/godotengine/godot/pull/78988.

I’ve managed to get something the crashes fairly regularly but not super consistently.

This project is setup with a player that can move with arrows and a keybind of r to restart the scene. When restarting the scene sometimes the game will crash. My best success at reproducing is to hold a direction with the arrows and tap r to restart and it will occasionally crash. hooking up xdb64 it seems to crash in something related to creating a thread? The crashes were more frequent in my actual game projects and they’re intermittent so it seems like some kind of race condition possibly.

Note: I only see crashes in non-debug builds on Windows. Running the project in the editor and Debug builds on windows never crash.

minimal-crash-repro.zip

So glad I found this topic was going mental because the game crashed sometimes on scene change and I had no idea why. Can confirm this is happening only during windows export without debug. With debug it all works. And only with scenes with many nodes in my small project with just scene change button it works flawlessly. v4.0.stable.official [92bee43ad] and v4.0.3.stable.official [5222a99f5]