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

No device and/or context creation failure on some hardware. #1118

Open
LMCrashy opened this issue Mar 4, 2025 · 6 comments
Open

No device and/or context creation failure on some hardware. #1118

LMCrashy opened this issue Mar 4, 2025 · 6 comments

Comments

@LMCrashy
Copy link

LMCrashy commented Mar 4, 2025

Hi,

I'm making a game and some of my players are having issues on their computers. Looking at the logs I see that either OpenAL doesn't find any device or the context creation fails.

I don't do anything complex and everything can be resumed to this:

mDevice = alcOpenDevice(NULL);
if(!mDevice)
{
	//log error
}

mContext = alcCreateContext(mDevice, 0);
if(mContext)
{
	//log error
}

It looks like it happens mostly on USB sound cards such as Sound Blaster GC7 and some USB headsets.

Unfortunately I don't have the error code returned because I didn't logged this information before and now I've fixed the crashes when sound system isn't initialized I don't receive reports any more.

However, I can say that there is a workaround for this, which is described here which is quite dumb: simply play a video on youtube before launching the game, and voilà. Note this also works if one's playing with the sound volume control of Windows that plays a little sound when touched.

I feel like for some reason OpenAL can't find or use devices if they're in some "sleep" mode, and playing some sound on the desktop "wake" them up.

As apart from my game at least another one have this issue, I guess I'm not the only one to encounter this.
By chance, does anybody know if there is something to prevent this ?

@kcat
Copy link
Owner

kcat commented Mar 4, 2025

Hi. Are you able to provide a trace log from OpenAL Soft? If you set the ALSOFT_LOGLEVEL environment variable to 3, OpenAL Soft will write a trace to the process's stderr. You can also set ALSOFT_LOGFILE to a path and filename to have it write the log to the given file instead.

@LMCrashy
Copy link
Author

LMCrashy commented Mar 7, 2025

Hi, sorry for the delay, I was waiting for someone to send me the logs.

Here it is

[ALSOFT] (II) Initializing library v1.24.2-unknown UNKNOWN
[ALSOFT] (II) Supported backends: wasapi, dsound, winmm, null, wave
[ALSOFT] (II) Loading config C:\Users\cturg\AppData\Roaming\alsoft.ini...
[ALSOFT] (II) Got binary: E:\steam\steamapps\common\Task Force Admiral Demo\bin\master, Launcher.exe
[ALSOFT] (II) Loading config E:\steam\steamapps\common\Task Force Admiral Demo\bin\master\alsoft.ini...
[ALSOFT] (II) Vendor ID: "AuthenticAMD"
[ALSOFT] (II) Name: "AMD Ryzen 5 2600X Six-Core Processor"
[ALSOFT] (II) Extensions: +SSE +SSE2 +SSE3 +SSE4.1
[ALSOFT] (II) Starting watcher thread
[ALSOFT] (II) Initialized backend "wasapi"
[ALSOFT] (II) Added "wasapi" for playback
[ALSOFT] (II) Added "wasapi" for capture
[ALSOFT] (II) Opening playback device "OpenAL Soft"
[ALSOFT] (II) Got device "Headset Earphone (4- CORSAIR VOID ELITE Wireless  Gaming Dongle)", "{20D3A911-D809-475D-B98E-3669BED40457}",  "{0.0.0.00000000}.{20d3a911-d809-475d-b98e-3669bed40457}"
[ALSOFT]  (II) Got device "32ML600 (NVIDIA High Definition Audio)",  "{2A180576-8E77-4C54-82B9-74EAC71A45CE}",  "{0.0.0.00000000}.{2a180576-8e77-4c54-82b9-74eac71a45ce}"
[ALSOFT]  (II) Got device "Speakers (High Definition Audio Device)",  "{BCEACA7F-118A-4B39-BA0C-DF5A7DE2E4BD}",  "{0.0.0.00000000}.{bceaca7f-118a-4b39-ba0c-df5a7de2e4bd}"
[ALSOFT]  (II) Got device "Headset Microphone (4- CORSAIR VOID ELITE Wireless  Gaming Dongle)", "{369AE8BC-866A-4459-8478-D9F53BFA8675}",  "{0.0.1.00000000}.{369ae8bc-866a-4459-8478-d9f53bfa8675}"
[ALSOFT] (II) Watcher thread started
[ALSOFT] (II) Created device 0x1582a15cbc0, "OpenAL Soft on Headset Earphone (4- CORSAIR VOID ELITE Wireless Gaming Dongle)"
[ALSOFT] (II) Pre-reset: Stereo, Float32, 48000hz, 960 / 2880 buffer
[ALSOFT] (II) Device mix format:
    FormatTag      = 0xfffe
    Channels       = 2
    SamplesPerSec  = 48000
    AvgBytesPerSec = 384000
    BlockAlign     = 8
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x3
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
[ALSOFT] (II) Requesting playback format:
    FormatTag      = 0xfffe
    Channels       = 2
    SamplesPerSec  = 48000
    AvgBytesPerSec = 384000
    BlockAlign     = 8
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x3
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
[ALSOFT] (II) Post-reset: Stereo, Float32, 48000hz, 480 / 2880 buffer
[ALSOFT] (II) Searching E:\steam\steamapps\common\Task Force Admiral Demo\bin\master for *.mhr
[ALSOFT] (II) Adding built-in entry "!1_Built-In HRTF"
[ALSOFT] (II) Loading !1_Built-In HRTF...
[ALSOFT] (II) Detected data set format v3
[ALSOFT] (II) Loaded HRTF Built-In HRTF for sample rate 48000hz, 64-sample filter
[ALSOFT] (II) 1st order + Full HRTF rendering enabled, using "Built-In HRTF"
[ALSOFT] (II) Channel config, Main: 4, Real: 2
[ALSOFT] (II) Allocating 6 channels, 24576 bytes
[ALSOFT] (II) Min delay: 7.75, max delay: 33.50, FIR length: 64
[ALSOFT] (II) New max delay: 25.75, FIR length: 90
[ALSOFT] (II) Max sources: 256 (255 + 1), effect slots: 64, sends: 4
[ALSOFT] (II) Dithering disabled
[ALSOFT] (II) Output limiter disabled
[ALSOFT] (II) Fixed device latency: 0ns
[ALSOFT] (II) Post-start: Stereo, Float32, 48000hz, 480 / 2880 buffer
[ALSOFT] (II) Increasing allocated voices to 256
[ALSOFT] (II) Created context 0x1582a180e10
[ALSOFT] (II) Freeing context 0x1582a180e10
[ALSOFT] (II) Freeing device 0x1582a15cbc0
[ALSOFT] (II) HrtfStore 0x1582a2504d0 decreasing refcount to 0
[ALSOFT] (II) Unloading unused HRTF !1_Built-In HRTF
[ALSOFT] (II) Opening default playback device
[ALSOFT] (II) Created device 0x1582a15cbc0, "OpenAL Soft on Headset Earphone (4- CORSAIR VOID ELITE Wireless Gaming Dongle)"
[ALSOFT] (II) Pre-reset: Stereo, Float32, 48000hz, 960 / 2880 buffer
[ALSOFT] (II) Device mix format:
    FormatTag      = 0xfffe
    Channels       = 2
    SamplesPerSec  = 48000
    AvgBytesPerSec = 384000
    BlockAlign     = 8
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x3
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
[ALSOFT] (II) Requesting playback format:
    FormatTag      = 0xfffe
    Channels       = 2
    SamplesPerSec  = 48000
    AvgBytesPerSec = 384000
    BlockAlign     = 8
    BitsPerSample  = 32
    Size           = 22
    Samples        = 32
    ChannelMask    = 0x3
    SubFormat      = {00000003-0000-0010-8000-00aa00389b71}
[ALSOFT] (EE) Failed to initialize audio client: 0x8889000a
[ALSOFT] (EE) Device error: Device init failed: 0x8889000a
[ALSOFT] (WW) Error generated on device 0x1582a15cbc0, code 0xa001
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)
[ALSOFT] (WW) Querying error state on null context (implicitly 0xa004)		

@kcat
Copy link
Owner

kcat commented Mar 7, 2025

Looks like IAudioClient::Initialize is returning AUDCLNT_E_DEVICE_IN_USE. According to the documentation:

The endpoint device is already in use. Either the device is being used in exclusive mode, or the device is being used in shared mode and the caller asked to use the device in exclusive mode.

The log doesn't show OpenAL Soft trying to open it in exclusive mode. Is there anything else running on the system that may periodically try opening the device in exclusive mode? Unfortunately since it's an error from the system about the device being unavailable, there isn't really much to do except try again after a moment. The error code AUDCLNT_E_DEVICE_IN_USE doesn't really indicate it being temporary, though.

The way the error happens in that log does seem a bit weird. It works the first time, gets closed, then fails to reopen the audio client right afterward due to the device being in use. This kind of behavior is something you'd sometimes see when using hardware directly; after closing a device it could take an extra moment for the hardware resources to be freed and become usable again. But using the device in shared mode through WASAPI should avoid that problem since it's the audio service managing the device state, and the apps/clients are simply providing a stream to the shared mode engine for it to mix together for output. The mentioned workaround, having a youtube video playing in the background, does seem to play into this behavior though, as it would basically force WASAPI to keep the hardware open and in use by the shared mode engine while OpenAL Soft opens, closes, and reopens its own device client(s).

If it's not the fault of some background process temporarily opening the device in exclusive mode, this would suggest a race condition in either WASAPI or the device driver. An app tries to open the device at the same moment the hardware is being put into a suspended/stopped state, but rather than waiting for the hardware to finish transitioning to a suspended/stopped state to be able to resume/start it again, it's inferred as the device being in-use.

@LMCrashy
Copy link
Author

LMCrashy commented Mar 7, 2025

Thanks for your answer !
What could I do to fix or workaround this issue ?
Would a simple sleep of some time, retry, again and again (with some limits to avoid infinite looping) do the job ? I must say that I'm not an expert on this specific topic and have only a very rough idea on how sound APIs works at lower level.

@kcat
Copy link
Owner

kcat commented Mar 7, 2025

The simplest solution would likely be to have a loop where you do a short delay (20 ms or so, probably) and try again, and break from the loop after it succeeds or a certain amount of time passes (or a certain number of attempts). I can't really give any guidance on how long to wait since I wouldn't expect this to happen to begin with, I don't know how much of a delay to expect, nor do I know what else your app may be trying to do at this point that would get held up by waiting. Maybe 1 or 2 seconds max is the longest I'd wait, if not shorter, but it's up to you. You wouldn't want to wait indefinitely since it can also be possible the device is actually in use by another process with exclusive access and won't be available any time soon.

@LMCrashy
Copy link
Author

LMCrashy commented Mar 9, 2025

Thank you, will try that and see what happens.

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

No branches or pull requests

2 participants