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():
$AudioStreamPlayer2D.play(0)
var world2d: World2D = world.get_world_2d()
viewport.world_2d = world2d
func _process(_delta):
if Input.is_action_just_pressed("DebugKeyAction1"):
get_tree().reload_current_scene()
Steps to reproduce:
Launch game
Press 1 (this reloads the scene and calls play() on ready)
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.
It was merged a long time ago, but maybe you found an edge case? Anyway, I would try to move $AudioStreamPlayer2D.play(0) 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?
Did you ever find a solution for this, I’m having the exact same thing in my project. Was there a GitHub issue posted for this? I’m on 4.3.stable
Some additional details from my own testing;
Delaying the AudioStreamPlayer2D.play() function, even by a very large amount doesn’t stop the crash.
I had guessed based off the affine inverse determinant error that the transform might be wrong, but both the local and global transforms print out as [X: (1, 0), Y: (0, 1), O: (0, 0)] which seems normal to me
This also happens when spawning the AudioStreamPlayer2D with autoplay enabled
If you setup the sound to play on key press, then you can see that the crash sometimes happens after playing the sound a few times (but always after reloading the scene at least once)