dechamps / FlexASIO

A flexible universal ASIO driver that uses the PortAudio sound I/O library. Supports WASAPI (shared and exclusive), KS, DirectSound and MME.
Other
1.35k stars 72 forks source link

Ableton crashes at startup when ASIO4ALL is also installed #86

Open motorboyxx opened 4 years ago

dechamps commented 4 years ago

For reference, there's a log at https://github.com/dechamps/FlexASIO/issues/83#issuecomment-674520269

--- ENTERING CONTEXT: start()
Starting PortAudio stream 00000000070946F0
[PortAudio] WASAPI: thread[ priority-0xD class-0x20 ]
[PortAudio] WASAPI ERROR HRESULT: 0x88890004 : AUDCLNT_E_DEVICE_INVALIDATED
FILE: C:\Users\edechamps\Documents\FlexASIO\src\portaudio\src\hostapi\wasapi\pa_win_wasapi.c {LINE: 5818}]
PortAudio stream started
--- EXITING CONTEXT: start() [OK]

I've never seen PortAudio fail on start() before and it looks like there's an error handling bug on the PortAudio side where the error doesn't percolate through to FlexASIO. Most likely PortAudio ends up in a messed up state and that's what's making the process crash.

AUDCLNT_E_DEVICE_INVALIDATED is being returned from IAudioClient::Start(). Again that's the first time I see this error code. According to the relevant docs this means:

The audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use.

Strangely, this error starts being returned earlier, during canSampleRate() probes. The last probe to succeed is for 96 kHz at 14:22:13.850, but then the next probe for 176.4 kHz at 14:22:13.880 fails with AUDCLNT_E_DEVICE_INVALIDATED. It's really strange that it's failing all of a sudden in the middle of a probe sequence with no apparent reason. If it's the probes themselves that are causing issues, then #66 might end up fixing this problem as a side effect.

dechamps commented 4 years ago

Off the top of my head I can only think of two hypotheses:

  1. Ableton probing sample rates after createBuffers() somehow results in PortAudio's internal state getting messed up, causing undefined behaviour.
  2. Ableton is attempting to initialize multiple audio outputs (perhaps multiple ASIO drivers, or even multiple output methods) at the same time during startup, and the parallel initialization procedures are racing against each other, resulting in device state getting messed up.

@motorboyxx Do you have other ASIO drivers installed? If so, can you try uninstalling them and see what happens? (You can also temporarily disable a driver by deleting its registry key under HKEY_LOCAL_MACHINE\SOFTWARE\ASIO, and restore it afterwards.)

motorboyxx commented 4 years ago

I do have ASIO4ALL installed as well. Disabling ASIO4ALL actually makes me able to launch with FlexASIO without crashing! Hopefully that will give you a clue!

dechamps commented 4 years ago

Okay, that actually makes some sense. If Ableton is attempting to concurrently initialize multiple ASIO drivers, then one of them might grab exclusive access to the hardware while FlexASIO is trying to probe it. This is exactly something that ASIO4ALL might do, since it uses WDM-KS internally which does imply exclusive access.

I'm not quite sure how I could make FlexASIO more resilient to this issue. Maybe it could try to detect this situation, or repeatedly retry failing PortAudio calls to try to circumvent races. I wish host applications would refrain from concurrently initializing multiple ASIO drivers at the same time - that's really playing with fire.

Until I come up with a fix, my suggestion would be to avoid having multiple ASIO drivers installed at the same time when using Ableton.

inwardmovement commented 1 year ago

Until I come up with a fix, my suggestion would be to avoid having multiple ASIO drivers installed at the same time when using Ableton.

Hi, I uninstalled every other ASIO drivers but still have a loud noise at Ableton startup. Do you have a definitive fix for this issue?

dechamps commented 1 year ago

This issue is about Ableton crashes on initialization due to racing with other ASIO drivers. What you are describing (loud noises) seems like a completely different and unrelated problem. Can you open a new issue and attach a log?