Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When there's no audio output device, AudioStreamPlayer finished signal isn't emitted #88775

Closed
Tracked by #76797
novalis opened this issue Feb 24, 2024 · 9 comments
Closed
Tracked by #76797

Comments

@novalis
Copy link
Contributor

novalis commented Feb 24, 2024

Tested versions

v4.2.1.stable.official.b09f793f5

System information

Windows 11 VM from Microsoft, in VirtualBox

Issue description

I'm running Godot using VirtualBox from a Windows 11 VM guest, Linux host. I haven't got audio set up yet, so there are no audio devices on the guest. I am playing a sound using:

	var player = AudioStreamPlayer.new()
	player.bus = "Foley"
	add_child(player)
	player.stream = load("res://example.mp3")
	player.play()
	await player.finished

On my Linux host, it works fine. On the Windows guest (with no audio device), finished is never emitted and the game just hangs in the await. Please insert Samuel Beckett joke here.

If I could detect the no-audio condition, I could avoid waiting on the signal, but I don't see a way to do that.

Steps to reproduce

I've attached a repro project; it's slightly different in that it doesn't use gdscript to await the signal, but the effect is the same: the finished signal is never fired.

The startup messages:

C:\Users\User\Desktop\no-audio>..\Godot_v4.2.1-stable_win64. exe --rendering-driver opengl3

C:\Users\User\Desktop\no-audio>Godot Engine v4.2.1.stable.official.b09f793f5 - https://godotengine.org

Mesa: SVGA3D; build: RELEASE;

Mesa: mesa-21.3.8
OpenGL API 4.1 (Core Profile) Mesa mesa-21.3.8 - Compatibility - Using Device: Mesa - SVGA3D; build: RELEASE;
ERROR: Condition "hr != ((HRESULT)0x00000000)" is true. Returning: ERR_CANT_OPEN
   at: audio_device_init (drivers/wasapi/audio_driver_wasapi.cpp:275)
ERROR: WASAPI: init_output_device error
   at: init (drivers/wasapi/audio_driver_wasapi.cpp:562)

Minimal reproduction project (MRP)

no-audio.zip

I'm using the VirtualBox VM from https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ on a Linux host.

@AThousandShips
Copy link
Member

AThousandShips commented Feb 24, 2024

As you can see it shows a clear error that it can't initialize audio, so I think it's expected that audio just doesn't work, I'm not sure how this should be solved or if any audio code should be running in this case

I suspect playback in various ways depends on the actual audio device behavior, and therefore can't reliably emit the signal if none is available

A dummy device could be used instead though, unsure how that works or would work though, for example a fallback


Edit: This sounds like a duplicate of this issue, which was solved recently for 4.3, and cherry picked for 4.2.2:

Please try 4.3.dev3 or 4.2.2.rc1, this should have been solved

@novalis
Copy link
Contributor Author

novalis commented Feb 24, 2024

Thanks for finding that previous issue. I just tried 4.3.dev3, but it doesn't work. I do see " WARNING:All audio drivers failed, falling back to the dummy driver.", so something has changed, but I still don't get the finished signal in my test project. Would you like me to keep this one open, or should we move the discussion to #71640?

@AThousandShips
Copy link
Member

Let's keep this open and see what else is needed there

@Calinou
Copy link
Member

Calinou commented Feb 27, 2024

audio_finished should definitely be emitted if there are no audio devices (or in headless mode), as it's frequently used to impact gameplay (e.g. queue_free() an enemy scene once their death sound is done playing).

@shandralor
Copy link

just confirmed this, through trial and error that every line below the audio_finished is never run if no sound device is attached or found. Is there any type of error handling that could be used to catch this?

@akien-mga akien-mga changed the title When there's no audio output device, AudioStreamPlayer finished signal isn't emitted When there's no audio output device, AudioStreamPlayer finished signal isn't emitted Apr 6, 2024
@akien-mga
Copy link
Member

Tested on 4.3-dev5, it seems to work as expected for me when using --headless or --audio-driver Dummy.

I modified the MRP to autoplay and print the state in the terminal to test:
no-audio.zip

I haven't tried in a Windows VirtualBox VM though, but if the fallback to the Dummy audio driver works correctly, it should work.

Could you test both with the automatic fallback when WASAPI fail (just running Godot normally), and with --audio-driver Dummy to see if there's a difference?

@akien-mga
Copy link
Member

akien-mga commented Apr 6, 2024

I installed a Windows 11 VM in VirtualBox to test, but I missed that there were custom ones on https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ and I did a plain Windows 11 Pro install from the main install ISO. The VM has working audio, so I can't reproduce the bug either 🙃

Edit: I disabled audio support in VBox, so I could reproduce WASAPI failing to initalize. Even then, the MRP works fine for me, it properly emits finished. So I'll consider this bug was indeed fixed, at least as of 4.3-dev5.

Please comment if you still reproduce it and provide more details on how you're testing.

@akien-mga
Copy link
Member

Fixed by #71640.

@akien-mga akien-mga added this to the 4.3 milestone Apr 6, 2024
@novalis
Copy link
Contributor Author

novalis commented Apr 9, 2024

Confirmed that with or without --audio-driver Dummy this works in dev5 on my win11-virtualbox-with-broken-audio.

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants