Author Topic: BASS_ASIO_Stop() doesn't wait for the ASIO device to close  (Read 29 times)

KaleidonKep99

  • Posts: 190
I've been trying to figure out why OmniMIDI crashes whenever I free up the BASS libraries with FreeLibrary while using the ASIO engine... Using BASS alone with DirectSound/WASAPI is fine, and allows me to free up BASS, BASSMIDI, BASSASIO and BASSenc without issues.

The issue seems to arise when freeing BASSASIO specifically.
I analyzed its behavior, and it doesn't seem to wait for the device to be closed.

My driver manages to free all the libraries and such just fine, the debug log reports that everything is fine:
Code: [Select]
16-11-2018 00:07:55.729 - Stage <<FreeUpStreamFunc>> | BASSASIO stopped.
16-11-2018 00:07:55.730 - Stage <<FreeUpStreamFunc>> | BASSASIO freed.
16-11-2018 00:07:55.730 - Stage <<FreeUpStreamFunc>> | BASS stream stopped.
16-11-2018 00:07:55.731 - Stage <<FreeUpStreamFunc>> | BASS stream freed.
16-11-2018 00:07:55.731 - Stage <<FreeUpStreamFunc>> | BASS stopped.
16-11-2018 00:07:55.731 - Stage <<FreeUpStreamFunc>> | BASS freed.
16-11-2018 00:07:55.731 - Stage <<CloseThreadsFunc>> | Closing audio thread...
16-11-2018 00:07:55.731 - Stage <<CloseThreadsFunc>> | Closing events processer thread...
16-11-2018 00:07:55.731 - Stage <<CloseThreadsFunc>> | Closing main thread...
16-11-2018 00:07:55.738 - Stage <<StreamWatchdog>> | Closing health thread...
16-11-2018 00:07:55.738 - Stage <<CloseThreadsFunc>> | Threads closed.
16-11-2018 00:07:55.738 - Stage <<FreeUpMemoryFunc>> | Freeing EV buffer...
16-11-2018 00:07:55.738 - Stage <<FreeUpMemoryFunc>> | Freed.
16-11-2018 00:07:55.738 - Stage <<FreeUpMemoryFunc>> | Freeing audio buffer...
16-11-2018 00:07:55.738 - Stage <<FreeUpMemoryFunc>> | Freed.
16-11-2018 00:07:55.738 - Stage <<StopDriver>> | Closing registry keys...
16-11-2018 00:07:55.745 - Stage <<StopDriver>> | Closed MainKey...
16-11-2018 00:07:55.746 - Stage <<StopDriver>> | Closed Configuration...
16-11-2018 00:07:55.746 - Stage <<StopDriver>> | Closed Channels...
16-11-2018 00:07:55.746 - Stage <<StopDriver>> | Closed ChanOverride...
16-11-2018 00:07:55.746 - Stage <<StopDriver>> | Closed SFDynamicLoader...
16-11-2018 00:07:55.746 - Stage <<StopDriver>> | Just a few more things...
16-11-2018 00:07:55.746 - Stage <<UnloadBASS>> | Freeing BASS libraries...
16-11-2018 00:07:55.751 - Stage <<UnloadBASS>> | The BASS libraries have been freed from the app's working set.
16-11-2018 00:07:55.751 - Stage <<StopDriver>> | Driver terminated.
16-11-2018 00:07:55.751 - Stage <<KDMAPI_TKS>> | KDMAPI is now in sleep mode.

Then, after a few milliseconds, the app just crashes with a bassasio.dll_unloaded error.


I already checked all my code, and there are no BASSASIO calls made while the library is not loaded into memory, since I added a check that prevents all BASS* calls to be made while the libraries are unavailable. (It's a boolean called BASSLoadedToMemory)

At first I thought that maybe the ASIO device is trying to send something to BASSASIO which is not available anymore, which then causes the buffer overflow exception, but again I'm not sure, since I don't know how BASSASIO communicates with the ASIO device.

Ian @ un4seen

  • Administrator
  • Posts: 21326
The thread created by the BASS_ASIO_THREAD option is closed asynchronously after a BASS_ASIO_Free call, so it isn't safe to immediately unload BASSASIO.DLL (because that BASSASIO thread is still running). Here's an update that will automatically delay the unloading until the thread has closed:

   www.un4seen.com/stuff/bassasio.zip

KaleidonKep99

  • Posts: 190
The update works perfectly! Thank you! ;D ;D