You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
if( result == paNoError )
{
...
}
else
{
//PA_DEBUG(("Loading result was NOT successful for:%d name = %s\n", driverIndex, deviceInfo->name));
**return PaErrorCode::paNotInitialized;**
}
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.
OS: [Win 11]
PortAudio version: latest on github (v.19.7.0)
ASIO
(A pull request could be made if this explanation is not clear enough to implement.)
The text was updated successfully, but these errors were encountered:
cuikp
changed the title
Asio driver present without device causes crash on PaAsio_Initialize
faulty Asio driver present (without device) causes exception crash on PaAsio_Initialize
Sep 13, 2024
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.)
The text was updated successfully, but these errors were encountered: