Open cuikp opened 2 months ago
I think it's worth submitting working code as a draft PR so that we know exactly what you're proposing.
Is there any way I could install this crashing driver?
Also, you wrote:
I find that the exception is thrown in the ASIO SDK
Where is the exception caught?
Recently began using portaudio via P/Invoke. Apparently portaudio attempts to load (and then unload) all ASIO drivers present on a given machine in PaAsio_Initialize(). However, if a driver is faulty and fails to load, portaudio will still try to unload it, causing an exception to be thrown.
This particular situation may be difficult to reproduce unless one purposely installs a faulty driver and then runs portaudio. As luck had it I happened to have a bad ASIO driver already on my system so I discovered the problem straightaway.
Tinkering with the source code, I find that the exception is thrown in the ASIO SDK in:
However, this code will not try to unload the (faulty) driver if lpdrv->asiodrv is nullptr, so this opens up a workaround (the following), which I have tested and thus managed to avoid the driver error.
In the static PaError InitPaDeviceInfoFromAsioDriver() method (pa_asio.cpp) I added the following in the else block:
That is, we can return the specific PaErrorCode of paNotInitialized when attempt to get the device info fails.
Then, I made the following change when the call is actually made from PaAsio_Initialize():
In other words, if the returned PaErrorCode is paNotInitialized, it loops through the LPASIODRVSTRUCT to find the current one, and sets its asiodrv to nullptr. Once set to nullptr, the SDK's methods AsioDriverList::asioCloseDriver() (as well as deleteDrvStruct() ) will skip trying to unload it, thus solving the problem.
(A pull request could be made if this explanation is not clear enough to implement.)