Author Topic: How can I recognize Asio devices that are in use?  (Read 1091 times)

udo

  • Posts: 93
Is there a possibility without initializing the device?
I have used this but often I get an exception instead of true/false:
Code: [Select]
BASS_ASIO_DEVICEINFO[] infos = BassAsio.BASS_ASIO_GetDeviceInfos();
for (int i = 0; i < infos.Length; i++)
{
    BASS_ASIO_DEVICEINFO deviceInfo = infos[i];
    Debug.WriteLine(deviceInfo.name);
    bool initres = BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_DEFAULT);
    if (initres)
    {
        BassAsio.BASS_ASIO_Free();
    }

    // some stuff collect results
   
}

Exception:
System.Runtime.InteropServices.SEHException
  HResult=0x80004005
  Message = An external component has triggered an exception.
  Source = <The exception source cannot be evaluated>.
  Stack monitoring:
<The exception stack monitor cannot be evaluated.>

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #1 on: 27 Nov '23 - 15:46 »
No, I don't think there is any way to tell if an ASIO device is in use besides trying to initialize it. Some devices/drivers will allow multiple users, so it may already be is use even if you can initialize it.

Regarding the exception, I guess that's coming from a particular ASIO driver. Please provide a dump file from it to have a look at. You can hopefully find a dump file in the "%LOCALAPPDATA%\CrashDumps" folder, and then upload it here:

   ftp.un4seen.com/incoming/

If you don't see a dump file there and you're currently running your app in the debugger, try running outside of the debugger and see if a dump file is generated then.

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #2 on: 29 Nov '23 - 17:18 »
The exception only seems to occur when the APP is running in the debugger. Without debugger no problem so far, and no dump file.
Any ideas?

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #3 on: 30 Nov '23 - 15:05 »
In that case, you can try the debugger's "Save Dump As" option in the "Debug" menu when it happens.

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #4 on: 30 Nov '23 - 17:06 »
Something is wrong with ftp. I was able to upload the dump file with Filezilla but it disappeared immediately.
WinSCP shows: Overwrite permission denied

If i change to
initres = BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_THREAD);
The APP crashed without Exception and i got a dump file in CrashDumps
« Last Edit: 1 Dec '23 - 08:07 by udo »

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #5 on: 1 Dec '23 - 13:14 »
Your upload was successful but the file isn't publicly visible afterwards (for confidentiality). The dump file shows that a C0000008 exception is happening in the ASIO driver when BASSASIO attempts to load it (before even trying to initialize it). That exception indicates that the driver tried to close an invalid handle (with CloseHandle), which doesn't necessarily mean the driver won't still work, ie. the BASS_ASIO_Init call may still succeed. Does it if you continue execution in the debugger?

Please also upload the dump file from the crash with BASS_ASIO_THREAD to have a look at.

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #6 on: 1 Dec '23 - 16:56 »
OK, uploadet a dump file with BASS_ASIO_THREAD crash.

After the Exception strange things can happen.
So i could not Init a device, Error was BASS_ERROR_ALREADY
After that i called BassAsio.Free(): BASS_ERROR_INIT

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #7 on: 1 Dec '23 - 18:01 »
OK, uploadet a dump file with BASS_ASIO_THREAD crash.

It's a different ASIO driver that caused an exception in this case, and it was while unloading (in BASS_ASIO_Free) rather than while loading (in BASS_ASIO_Init). Here's a BASSASIO update that will hopefully catch it to prevent a crash:

   www.un4seen.com/stuff/bassasio.zip

Let me know if you still see this exception (outside of a debugger).

After the Exception strange things can happen.
So i could not Init a device, Error was BASS_ERROR_ALREADY
After that i called BassAsio.Free(): BASS_ERROR_INIT

That does sound strange. Are you getting the BASS_ERROR_ALREADY error from the same BASS_ASIO_Init call that the exception happened in, or is it a different call? If a different one, what was the result of the exception's call?

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #8 on: 3 Dec '23 - 11:53 »
Quote
www.un4seen.com/stuff/bassasio.zip
Thanks, i will try it

Quote
That does sound strange. Are you getting the BASS_ERROR_ALREADY error from the same BASS_ASIO_Init call that the exception happened in, or is it a different call? If a different one, what was the result of the exception's call?

This can only happen if i try to init with BASS_ASIO_DEFAULT.
Now i use try/except:
Code: [Select]
BASS_ASIO_DEVICEINFO[] infos = BassAsio.BASS_ASIO_GetDeviceInfos();
for (int i = 0; i < infos.Length; i++)
{
    BASS_ASIO_DEVICEINFO deviceInfo = infos[i];
    bool initres = false;
    bool err = false;
    try
    {
        initres = BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_DEFAULT);
        if (initres)
        {
            bool ok = BassAsio.BASS_ASIO_Free();
            if (!ok)
                Debug.WriteLine("ERROR Free: " + BassAsio.BASS_ASIO_ErrorGetCode() + " " + deviceInfo.name);
        }
        else
        {
            Debug.WriteLine("INIT ERR: " + BassAsio.BASS_ASIO_ErrorGetCode() + " " + deviceInfo.name);
        }
    }
    catch (Exception ex)
    {
        log += $"{deviceInfo.name}: {ex.Message}{Environment.NewLine}";
        err = true;
    }

    Hashtable ht = new Hashtable
    {
        { "ID", i },
        { "NAME", deviceInfo.name },
        { "NAMEORG", deviceInfo.name },
        { "TYPE", "ASIO" },
        { "INUSE", !initres },
        { "AC", deviceInfo.name.Equals("AcourateASIO") },
        { "ERROR", err },
    };
    devices.Add(ht);
}

It probably depends on which devices are active/in use, so it is not always the same device.
The exception does not always occur. Maybe the init worked internally anyway when the exception occurs.
A later init sometimes led to the strange behavior.
Maybe it is important to know that functions are not always executed by the same thread
(I also had problems to stop the BassTimer if this does not happen in the creator thread, Stop() does not come back)
« Last Edit: 4 Dec '23 - 09:01 by udo »

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #9 on: 5 Dec '23 - 08:22 »
Quote
It's a different ASIO driver that caused an exception in this case, and it was while unloading (in BASS_ASIO_Free) rather than while loading (in BASS_ASIO_Init). Here's a BASSASIO update that will hopefully catch it to prevent a crash:

   www.un4seen.com/stuff/bassasio.zip

Let me know if you still see this exception (outside of a debugger).

So far no crash with the new dll and BASS_ASIO_THREAD

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #10 on: 15 Jan '24 - 16:15 »
Unfortunately, the crash-problem still exists.
May I upload the new dump file?

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #11 on: 15 Jan '24 - 16:42 »
Sure, you can upload it here:

   ftp.un4seen.com/incoming/

There was another BASSASIO update since the one posted above, so please get that first and use it when generating the dump file:

   www.un4seen.com/stuff/bassasio.zip

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #12 on: 15 Jan '24 - 19:21 »
OK, its uploaded.

In Debugger i got this now at
BassAsio.BASS_ASIO_ChannelGetLevel(false, 0);

System.AccessViolationException
  HResult=0x80004003
  Message = An attempt was made to read or write in the protected memory. This is often an indication that other memory is corrupted.
  Source = <The exception source cannot be evaluated>.
  Stack monitoring:
<The exception stack monitor cannot be evaluated.>

BASS_ASIO_ChannelGetLevel is called by a Timer, if i dont start the timer no crash.


Perhaps important: Functions are always called by different threads.
That's probably why I always have problems with the BASSTimer, Stop() does not return.

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #13 on: 16 Jan '24 - 15:09 »
The dump file shows where the crash occurred, but it isn't clear how it came to that. Might BASS_ASIO_Free have been called at the same time in another thread? Anyway, here's an update with a little modification for you to try:

   www.un4seen.com/stuff/bassasio.zip

If you still get the crash with that, please upload a new dump file to have a look at.

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #14 on: 16 Jan '24 - 18:13 »
The dump file shows where the crash occurred, but it isn't clear how it came to that. Might BASS_ASIO_Free have been called at the same time in another thread?

Maybe it is a .NET problem. Because the first BASS_ASIO_Free happens in the main thread I tried a Tread.Sleep(2000) afterwards and there is no crash.

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #15 on: 17 Jan '24 - 14:30 »
I think it's unlikely that .Net would have caused the problem, but I'm not sure what did. The dump file didn't show any threads in a BASS_ASIO_Free call but perhaps a call had just returned? Did the update above help or do you still get the crash (without the Sleep)?

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #16 on: 26 Feb '24 - 08:47 »
There were crashes with Asio again. It seems to be dependent on the DAC(Asio driver).
Unfortunately I can't upload a dump, your FTP server rejects the connection. Error 530 Login incorrect.

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #17 on: 26 Feb '24 - 12:23 »
You need to login with username "anonymous" and any email address as the password. Your FTP client should (usually) do that automatically if you leave them blank.

udo

  • Posts: 93
Re: How can I recognize Asio devices that are in use?
« Reply #18 on: 26 Feb '24 - 21:42 »
Hmm, i used the same connect of last time.
dump is uploaded...

Ian @ un4seen

  • Administrator
  • Posts: 26177
Re: How can I recognize Asio devices that are in use?
« Reply #19 on: 27 Feb '24 - 12:36 »
This crash was in a CloseHandle call by the ASIO driver (ysusb_asio32) within a BASS_ASIO_Free call. I think the BASSASIO update posted in reply #7 should catch it, so please try with that (or a newer update) and see if it still happens then.