eliasdaler / edbr

Elias Daler's Bikeshed Renderer (Vulkan renderer/game engine)
416 stars 21 forks source link

OpenAL fails to create device/audio context sometimes #2

Open eliasdaler opened 3 months ago

eliasdaler commented 3 months ago

Reported by @erwincoumans. Overall, OpenAL initialization code is somewhat wonky and needs to be improved + would be nice to run games without audio at all.

erwincoumans@master-node:~/dev/edbr-build$ games/platformer/platformer
[ALSOFT] (WW) Failed to open playback device: Could not open /dev/dsp: No such file or directory
[ALSOFT] (WW) Error generated on device (nil), code 0xa004
ERROR: Failed to create OpenAL device
[ALSOFT] (WW) Error generated on device (nil), code 0xa001
ERROR (/home/erwincoumans/dev/edbr/edbr/src/Audio/SoundDevice.cpp: 78)
ALC_INVALID_DEVICE: a bad device was passed to an OpenAL function
ERROR: Could not create OpenAL audio context
eliasdaler commented 3 months ago

@erwincoumans, can you please provide some more details about your environment? (OS, compiler, etc.)

After running platformer, got this error btw, would be nice to run it without audio, eager to see Vulkan in action.

Does this only happen when running the platformer? Does audio work in mtpgame?


Also, please try to un-comment the following line in Audio/SoundDevice.cpp:

#define DEBUG_AUDIO_DEVICE // <--- this one

#ifdef DEBUG_AUDIO_DEVICE
...

It should output something like this in the console which might help me investigate the problem:

Found OpenAL device: Steinberg UR22C Analog Stereo
Default OpenAL device: Steinberg UR22C Analog Stereo
HRTF supported: true
Num HRTFs found: 2
Available HRTFs:
    0: Default HRTF
    1: Built-In HRTF
Using default HRTF...
OpenAL version: 1.1 ALSOFT 1.23.1
OpenAL vendor: OpenAL Community
OpenAL renderer: OpenAL Soft
Sample rate: 48000
erwincoumans commented 3 months ago

This is on Ubuntu 22.04, setting up audio can be tricky.

Does this only happen when running the platformer? Does audio work in mtpgame?

It happens in both games. I fiddled a bit more with Alsa/libasound2, PulseAudio, pipewire, no luck.

define DEBUG_AUDIO_DEVICE // <--- this one

OK, here is the output using the DEBUG_AUDIO_DEVICE definition:

''' erwincoumans@master-node:~/dev/edbr-build$ games/mtp/mtpgame [ALSOFT] (WW) Failed to initialize backend "pulse" Default OpenAL device: OpenAL Soft [ALSOFT] (WW) Failed to open playback device: Could not open /dev/dsp: No such file or directory [ALSOFT] (WW) Error generated on device (nil), code 0xa004 ERROR: Failed to create OpenAL device HRTF supported: false [ALSOFT] (WW) Error generated on device (nil), code 0xa001 ERROR (/home/erwincoumans/dev/edbr/edbr/src/Audio/SoundDevice.cpp: 78) ALC_INVALID_DEVICE: a bad device was passed to an OpenAL function ERROR: Could not create OpenAL audio context

'''

How about an option run the game with a no-audio / dummy audio option? Or detect the error and fallback without audio, instead of crashing?

eliasdaler commented 3 months ago

Tried to fix it here: https://github.com/eliasdaler/edbr/commit/2aeeed118d076825995951840fcee0be4e9940ed

This should fallback to "null audio" and would probably work.

I'll also investigate how to handle possible openal-soft/pulse audio issues a bit later. :)