Game crashing on AudioStreamPlayer2D play()

Godot Version




I’m having an issue where my game crashes when AudioStreamPlayer2D calls play(), after the scene has been reloaded. The scene contains a viewport that takes in the World2D of the scene’s root node.

Some observations I’ve noticed:

  • This isn’t observed when World2D isn’t shared with the viewport
  • This isn’t observed if play() isn’t called on the AudioStreamPlayer2D
  • This isn’t observed if there is no mp3 in AudioStreamPlayer2D
  • The game does not crash when stepping through with debug mode
  • When the game doesn’t crash, there is a frequent affine_invert: Condition ’ det == 0 ’ is true
  • This is only observed with AudioStreamPlayer2D and not the parent: AusioStreamPlayer

I can’t attach the project, but it is fairly simple to reproduce with the following scene setup and code:

extends Node2D

@onready var world : Node2D = $"."
@onready var viewport: SubViewport = $SubViewport

func _ready():
	var world2d: World2D = world.get_world_2d()
	viewport.world_2d = world2d

func _process(_delta):
	if Input.is_action_just_pressed("DebugKeyAction1"):

Steps to reproduce:

  1. Launch game
  2. Press 1 (this reloads the scene and calls play() on ready)
  3. If it doesn’t work, keep pressing 1. Or reload the game and try again. Also check debugger output.

I suspect I’m using the nodes wrong, but I would like to have a similar setup (use viewports, use AudioStreamPlayer2D). If you have a fix please let me know.

Thank you :slight_smile:

From my naive intuition, the first thing I would do is move play() after setting World2D, maybe memory problems on the reload sequence.

Could it be related to this problem? Fix 2D audio in multiple viewports by KoBeWi · Pull Request #76713 · godotengine/godot · GitHub

It was merged a long time ago, but maybe you found an edge case? Anyway, I would try to move $ to the end of the _ready() function.

Try removing the “0” from Play, leave just Play(), because when I was working with this node, I didn’t need to pass any arguments to this function.
P.S. I have looked at the documentation, I think the error is not in this, for 0 means start from zero second. Although it is specified as the default value, but if you remove 0, the program logic will not change.

Thanks for the suggestion.
Tried it but same error.

It might be worth mentioning that the game crashes after a random amount of reloads, and that sometimes, the audio appears closer/louder, but there’s no code to do this?

Do you think it’s worth posting as an issue on Godot’s github?

Definitely. At least you would know whether it is a real bug or not.

1 Like