Author Topic: BASS_Free getting stuck?  (Read 969 times)

Gargaj

  • Posts: 4
BASS_Free getting stuck?
« on: 8 Jun '16 - 17:05 »
I've been having this issue for a while now: BASS (latest version) works correctly until I try to deallocate, upon which the execution stops at the BASS_Free() call indefinitely.

This is how my code looks like: https://github.com/Gargaj/Bonzomatic/blob/master/src/platform_common/FFT.cpp

It is entirely possible I'm doing something wrong, but I'm not entirely sure what, and I'm pretty sure this used to work until I updated to 2.4.12

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Free getting stuck?
« Reply #1 on: 8 Jun '16 - 17:14 »
What platform are you having the problem on? If Windows, please generate a dump file when the problem happens using Task Manager's "Create Dump File" option and upload that to have a look at here:

   ftp.un4seen.com/incoming/

Please use this latest BASS.DLL build when doing that:

   www.un4seen.com/stuff/bass.zip

Gargaj

  • Posts: 4
Re: BASS_Free getting stuck?
« Reply #2 on: 8 Jun '16 - 17:26 »
Done (minidump-cf-bass_free-getting-stuck.zip)

I also included the software using BASS next to the ZIP in case you want to give it a try.

Gargaj

  • Posts: 4
Re: BASS_Free getting stuck?
« Reply #3 on: 8 Jun '16 - 17:32 »
I also uploaded the same thing when ran in Release mode (minidump-cf-bass_free-getting-stuck-release.zip).

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Free getting stuck?
« Reply #4 on: 9 Jun '16 - 12:39 »
Thanks for the dump files. They reveal that it's getting stuck in a Release call on the IDirectSound8 object. The call stack looks like this:

Quote
ntdll_77cf0000!ZwWaitForMultipleObjects+0x15
KERNELBASE!WaitForMultipleObjectsEx+0x100
kernel32!WaitForMultipleObjectsExImplementation+0xe0
kernel32!WaitForMultipleObjects+0x18
dsound!WaitObjectArray+0x17
dsound!WaitObject+0x15
dsound!CloseThread+0x2a
dsound!CThread::Terminate+0x57
dsound!CLeapRenderDevice::Uninitialize+0x73
dsound!CLeapRenderDevice::~CLeapRenderDevice+0x55
dsound!CLeapRenderDevice::`scalar deleting destructor'+0xd
dsound!CDsBasicRuntime::Release+0x26
dsound!CDirectSound::~CDirectSound+0x7e
dsound!CDirectSound::`scalar deleting destructor'+0xd
dsound!CDsBasicRuntime::Release+0x26
dsound!CDscomUnknown::NonDelegatingRelease+0x8
dsound!CDscomUnknown::Release+0x1e
dsound!CImpUnknown::Release+0x39
dsound!CImpDirectSound<CDirectSound>::Release+0x11
bass!BASS_Free+0x43

DirectSound appears to be stuck waiting for a worker thread to terminate. I do see a DirectSound thread in a "CDirectSoundAdministrator::HandleFocusChange" call, so perhaps that's what it's waiting for. If so, from the function name, it sounds like it could be related to the window handle that DirectSound was given during initialization. I notice you're passing a NULL handle to BASS_Init, which means that it will give DirectSound the desktop window handle. That usually works fine, but perhaps not in your case for some reason. Are you creating any windows? If so, you could try using that handle in the BASS_Init call.

It doesn't look like you really need the BASS_Init/Free calls though, as you're only getting FFT data from a recording channel?

Gargaj

  • Posts: 4
Re: BASS_Free getting stuck?
« Reply #5 on: 9 Jun '16 - 13:15 »
I was avoiding passing the HWND because I'm hoping to keep it cross-platform and it wasn't really documented what BASS_Init expects as the wnd parameter on OSX/Linux, so I figured NULL would be fine.

And yes, BASS_Init in itself is entirely unnecessary because I'm an idiot :) I've never used the recording features of BASS so I just thought it's something that's necessary for either operation :)

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Free getting stuck?
« Reply #6 on: 9 Jun '16 - 17:32 »
Yep, you can use NULL for the "win" parameter on other platforms (the parameter is ignored), but you should try to use a window handle on Windows, if you have one :)

Timtam

  • Posts: 18
Re: BASS_Free getting stuck?
« Reply #7 on: 30 May '18 - 19:03 »
Hi,

I'm just facing the same issues here.
I'm currently developing a Total Commander plugin using BASS.
The plugin procedure works like follows:
* DLL loads at some point
* Whenever Total Commander wants to load the plugin, it calls a method, giving a window handle as argument (the Total Commander parent window). The plugin should now create an own child window to do its stuff.
* Now, it can either tell the plugin to simply do something with the next file within the same child window, or, if the user wants so, open another child window to do their work.
* It will then call a function to clean up the child windows (once per window).

I used to call BASS_Init() once per window creation function, knowing that I actually just need to do it once and the other attempts will fail, due to BASS already being initialized.
I also called BASS_Free() whenever a child window gets destroyed, leading to a freed BASS whenever the second, but not first, window gets closed.
Not that this is just bad performance, I thought it would be more error-prune to call BASS_Init() once at dll loading time and BASS_Free() on dll shutdown.

Now there is the problem that I don't have a window handle at dll loading time yet.
I just tried the obvious and called BASS_Init() with NULL and encountered the same problem with the latest officially released BASS version, BASS_Free() gets stuck and Total Commander will never close completely (the window disappears but the process stays active in Taskmanager).
I then tried a mixture like you suggested above, calling BASS_Init() whenever TC wants me to create a window, handing over the window handle to BASS, but same result with BASS_Free() when called on DLL_PROCESS_DETACH.

Any ideas? Do you want me to send in a minidump as well?

Best Regards.

Timtam

Ian @ un4seen

  • Administrator
  • Posts: 21329
Re: BASS_Free getting stuck?
« Reply #8 on: 31 May '18 - 15:16 »
A window handle is only needed when using DirectSound output. The current BASS version (2.4.13) defaults to using WASAPI output instead, so a window handle isn't actually needed then (you can use NULL). In your case, it sounds like the problem may be that you're calling BASS_Init and/or BASS_Free from a DllMain function? It isn't safe to call them from there (it's generally unsafe to call functions from any DLL except KERNEL32.DLL there).

Timtam

  • Posts: 18
Re: BASS_Free getting stuck?
« Reply #9 on: 9 Jun '18 - 21:34 »
Hi,

thanks for that hint. I fixed it already by counting how many windows are currently active and initializing / freeing BASS whenever the count tells me to (either 1 to initialize or 0 to free). That works just fine.

Best Regards.

Timtam