App crashes on scene switch

Godot Version

Godot V4.6.1
Godot XR Tools 4.5.0
OpenXR Vendors Plugin 4.3.0

Run on Meta Quest 3

Question

Hello again,

I’m using the XR Tools staging mechanism to switch from my main menu to a second scene and then back to the main menu. This works fine so far.

However, when I programmatically load a 3D model and later delete it using node.queue_free(), the application crashes when switching back to the main menu.

I first noticed this problem after updating to Godot 4.6, although I’m not sure whether it’s actually related to the engine.

Things I have already tried:

  • Remote debugging is not very helpful because I end up stepping through _process() functions.
  • Using print statements doesn’t help much either. The issue seems to have a timing component, so sometimes the messages appear and sometimes they don’t.
  • I captured a crash report using adb. It shows the memory violation but doesn’t indicate where it occurs.
syscall: running
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x00000000000000e0
Cause: null pointer dereference

If anyone has suggestions on how I could further analyze or debug this issue, any help would be greatly appreciated.

I’m starting to run out of ideas at this point.

Make sure that when you manually queue free a node, you also remove it from the scene tree.
When the scene is unloaded, the nodes in the scene are freed as well. It sounds like this crash may be caused by double freeing that same node.

1 Like

Thanks for the hint!

I currently add the model with this code (in my gdscript/media manager node):

add_child(mediaModelNode)

and remove it again with this code:

func _close_item_media() -> void:
	if mediaModelNode != null:
		remove_child(mediaModelNode)
		mediaModelNode.queue_free()
		mediaModelNode = null

which seemed to work well. And there is no problem loading several models after each other (no memory leak, as far as i can see it), only when switching the scene.

The model itself is created reading a GLB from a ZIP file:

var modelData = zipReader.read_file(modelFile)
var result = gltfDocument.append_from_buffer(modelData, "", gltfState, 64)
...
mediaModelNode = gltfDocument.generate_scene(gltfState)

Is there anything else i have to do to remove a node from the scene tree?

I noticed that the 3D model is not causing the problem. The error occurs even if i don’t load the model. So i guess i’m not properly cleaning up something else in the scene tree.

Thanks for pointing me to that direction! :+1:

Indeed, your code looks correct, so it has to be coming from somewhere else.

Does it also crash in PCVR mode? It should give a full stack trace which may give a better hint as to why its crashing.

Does it also crash in PCVR mode? It should give a full stack trace which may give a better hint as to why its crashing.

I’m developing under Linux and SteamVR + Steam Link + starting my app in Godot crashes SteamVR with a critical error. :face_with_spiral_eyes:

I guess this setup is not ideal and i’ll have to wait for Steam Frame to get PCVR stack traces. :laughing:

Until then i found what is causing the problem, but i don’t understand it.

With the following scene:

calling

get_parent().find_child("SecondaryPanelOpenXRCompositionLayerQuad").visible = false

in the CollectionStarter’s script, and then leaving to the main scene, causes the crash.

This is always happening, no matter if i modify the composition layer’s content or not.

I have absolutely no clue, why that is causing the crash now. :man_shrugging:

I finally had time to reproduce the problem in a minimal project and am now quite certain that it is a bug.

Therefore, I created the following ticket: Segmentation Fault with OpenXRCompositionLayer and Staging · Issue #791 · GodotVR/godot-xr-tools · GitHub

However, I’m unsure whether the issue actually lies in the Godot XR Tools or in the engine itself.

Cool, does indeed sound like a problem in Godot itself, XR Tools doesn’t do anything particular with composition layers.

OK, thanks for the explanation, i will then “move” the ticket to the Godot project. :+1: