Author Topic: Issue with BassVst.BASS_VST_GetInfo  (Read 2743 times)

kafffee

  • Posts: 252
Issue with BassVst.BASS_VST_GetInfo
« on: 19 Jul '23 - 11:31 »
Hi everybody  :)

I am having a little issue with this line of code:

Code: [Select]
If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) AndAlso vstInfo.hasEditor Then
I am getting a System.AccessViolationException with this message (It's actually in German but I translated the best way I can):

It was tried to read or write in protected memory. This may be a hint that other memory is damaged.

And in German:

Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist.

I don't know how to fix this at all. Can anybody help?

PS: When I do this...:

Code: [Select]
If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) Then
If vstInfo.hasEditor Then

The application just exits, without an error....

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #1 on: 19 Jul '23 - 13:54 »
Is it the BASS_VST_GetInfo or BASS_VST_HasEditor call that's crashing, or do both crash? Try separating the calls and stepping over them in the debugger to confirm. Please also confirm whether the crash is happening with a particular VST or all.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #2 on: 19 Jul '23 - 17:09 »
 Okay, I separated them. The first call seems to be working, the second the program just exits. Other than when I not separate the calls, the above mentioned error shows up.

Some vst DLLs work fine, other end up like just said, and others the program hang up and does not respond any more, even before the above mentioned calls are made, when I do something Else on the UI...

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #3 on: 19 Jul '23 - 17:57 »
Okay, I separated them. The first call seems to be working, the second the program just exits. Other than when I not separate the calls, the above mentioned error shows up.

The program just exits on the "If vstInfo.hasEditor Then" line? Are you certain about that, ie. you've stepped through the code in the debugger and it just exits on that line?

BASS_VST_HasEditor internally calls BASS_VST_GetInfo and checks the "hasEditor" value, so please try replacing both lines with a call to that and see whether the crash still happens.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #4 on: 19 Jul '23 - 18:01 »
Yes I have done single line steps in the debugger.

With what call should I replace that? Just anything?

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #5 on: 19 Jul '23 - 18:20 »
Replace this:

Code: [Select]
If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) Then
If vstInfo.hasEditor Then

With this:

Code: [Select]
If BassVst.BASS_VST_HasEditor(VSTInstrumentChannel) Then

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #6 on: 19 Jul '23 - 19:13 »
Sounds good. Is that a new function though respectively is is called differntly in Bass. NET. dll?
I might use a version thats too old did not quite switch to a current version yet...

I get the error BASS_VST_HasEditor is not a member of BassVst...

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #7 on: 20 Jul '23 - 12:49 »
Indeed, it looks like the BASS_VST_HasEditor function isn't currently included in BASS.Net. For now, I think you can import the function yourself, something like this:

Code: [Select]
Declare Function BASS_VST_HasEditor Lib "bass_vst.dll" (vstHandle As Integer) As Boolean

Or like this:

Code: [Select]
<DllImport("bass_vst.dll")>
Public Shared Function BASS_VST_HasEditor(vstHandle As Integer) As Boolean
End Function

And then remove the "BassVst." prefix from the BASS_VST_HasEditor call.

Another thing you could try is BASS.Net's other BASS_VST_GetInfo overload:

Code: [Select]
Dim vstInfo As BASS_VST_INFO = BassVst.BASS_VST_GetInfo(VSTInstrumentChannel)
If Not (vstInfo Is Nothing) Then
  If vstInfo.hasEditor Then

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #8 on: 20 Jul '23 - 18:09 »
Nope none of them actually works. I keep getting this type of error....

Any other ideas?

Edit:

I have done some further testing and heres what I found out:

In a test program, the VST DLL works fine, just not in my main project:

The code of the test program:

Code: [Select]
VSTInstrumentChannel = BassVst.BASS_VST_ChannelCreate(44100, 2, "C:\Sketch Trumpet.instruments\Sketch Trumpet.dll", 0)
       
        Bass.BASS_ChannelPlay(VSTInstrumentChannel, False)
        Dim vstInfo As New BASS_VST_INFO()
        If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) AndAlso vstInfo.hasEditor Then
            Dim f As New Form()
            f.Width = vstInfo.editorWidth + 4
            f.Height = vstInfo.editorHeight + 34
            AddHandler f.Closing, AddressOf Form1_Closing
            f.Text = vstInfo.effectName
            f.Show()
            BassVst.BASS_VST_EmbedEditor(VSTInstrumentChannel, f.Handle)
        Else
            MessageBox.Show("No Editor!!")
        End If

The code of the main project:

Code: [Select]
Dim OKVM = New OKDialogViewModel
        Dim vstInfo As New BASS_VST_INFO()
        Bass.BASS_ChannelPlay(VSTInstrumentChannel, False)
        If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) Then
            If vstInfo.hasEditor Then


                EmptyVM = New ViewModel.EmptyViewModel("Instrument " & CStr(WhichInstance + 1) & ": " & vstInfo.effectName, VSTInstrumentChannel, ChosenInstrument, Me)
               
                WindowHandle = WindowService.OpenPlugInWindow("Instrument " & CStr(WhichInstance + 1) & ": " & vstInfo.effectName, vstInfo.editorHeight + 28, vstInfo.editorWidth, EmptyVM, Me)
               
                EmptyVM.UIHandles = WindowHandle
               
                If UIOpen Then
                    OKVM = New OKDialogViewModel
                    OKVM.Meldung = "UI already open."
                    dialogService.ShowModalDialog("", OKVM, Me, True, False, Services.WindowStyle.None, Services.ResizeMode.NoResize, 500, Services.SizeToContent.Height, Services.WindowStartupLocation.CenterOwner, "")
                Else
                    BassVst.BASS_VST_EmbedEditor(VSTInstrumentChannel, WindowHandle(0))
                    UIOpen = True
                    ChosenInstrument.UIOffen = True
                End If
            End If
        Else
            OKVM = New OKDialogViewModel
            OKVM.Meldung = "No User-Interface."
            dialogService.ShowModalDialog("", OKVM, Me, True, False, Services.WindowStyle.None, Services.ResizeMode.NoResize, 500, Services.SizeToContent.Height, Services.WindowStartupLocation.CenterOwner, "")
           
        End If

I also tried that with Declare Function BASS_VST_HasEditor as you described and then it works, but when it comes to EmbdeEditor the error will happen again.

So I did the same thing with Declare Function BASS_VST_EmbedEditor but still the error shows up...

I also gave you some wrong information, sorry about that:

When I do this:
Code: [Select]
If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) Then
            If vstInfo.hasEditor Then

The error occurs in the first line.
« Last Edit: 21 Jul '23 - 07:27 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #9 on: 21 Jul '23 - 12:29 »
Does it still crash if you remove the code from the "if" blocks? Like so:

Code: [Select]
        Dim vstInfo As New BASS_VST_INFO()
        Bass.BASS_ChannelPlay(VSTInstrumentChannel, False)
        If BassVst.BASS_VST_GetInfo(VSTInstrumentChannel, vstInfo) Then
            If vstInfo.hasEditor Then
            End If
        Else
        End If

If that's fine, then try putting the code back in and step through it in the debugger to hopefully find the line causing the crash.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #10 on: 21 Jul '23 - 13:25 »
No when I do that the program just exits completely without any error and when I add that Declare Function the error occurs again...
« Last Edit: 21 Jul '23 - 13:35 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #11 on: 21 Jul '23 - 13:55 »
OK, and when you step through the code in the debugger, it's exiting on the BASS_VST_GetInfo line?

What happens if you also remove the BASS_ChannelPlay call?

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #12 on: 21 Jul '23 - 14:25 »
Yes. I put a breakpoint on BASS_VST_GetInfo and execute. Fine So far. Then when it stops I execute again - - > it exits.

Same thing when I remove ChannelPlay...

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #13 on: 21 Jul '23 - 15:07 »
After hitting the breakpoint, please use the debugger's "Step Over" option (F10) instead of execute/continue, as the latter doesn't locate the problem to that particular line (it could be any line after).

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #14 on: 21 Jul '23 - 15:54 »
In Visual Studio, there are two options (I dont know what they are actually called in English but I translated):
Single Step and procedure step. I did single step. With the result that the code Sometimes ends up in a function that should not even be called and Sometimes I get the error in the BASS_VST_GETIinfo call

Edit: okay I checked that and it's okay for this mentioned function to be called.

So now I am at a point where Sometimes, the UI of the vst Shows up, Sometimes not, whithout any made changes in the code. I really cant determine why Sometimes it works and sometimes not... But it seems like when I wait a while when this mentioned function is called and then continue with a Single step it works. Yes, I have tried that two ore three times now...
« Last Edit: 21 Jul '23 - 16:26 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #15 on: 21 Jul '23 - 17:47 »
In Visual Studio, there are two options (I dont know what they are actually called in English but I translated):
Single Step and procedure step. I did single step. With the result that the code Sometimes ends up in a function that should not even be called and Sometimes I get the error in the BASS_VST_GETIinfo call

I guess the default shortcut keys will be the same in all languages, in which case pressing F10 should get you "Step Over".

So now I am at a point where Sometimes, the UI of the vst Shows up, Sometimes not, whithout any made changes in the code. I really cant determine why Sometimes it works and sometimes not... But it seems like when I wait a while when this mentioned function is called and then continue with a Single step it works. Yes, I have tried that two ore three times now...

OK. So is the problem now just that the VST's UI doesn't appear, rather than the entire app exits/crashes? If you aren't already doing so, make sure to check all return values to find out if any calls are failing.

If the problem persists but never happens with your test program, then I would suggest comparing the code differences to try to find the cause. If it still isn't apparent, then you could also try copying code one way or the other so see if/how that affects the result and hopefully find the cause that way.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #16 on: 22 Jul '23 - 06:24 »
No matter what I do, the program either crashes with that error, exits, or it actually works. The funny thing it crashes/exits in different lines.

Same thing when I copy the code from the test program.

When it works the Error codes are all 0....

Are these bass call being executed asynchronously or something like that? Maybe there is some way to wait for the Bass.dll calls to be completely done?

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #17 on: 24 Jul '23 - 16:06 »
I believe all of the BASS_VST function calls are synchronous, but the main processing will usually be asynchronous, ie. during playback. Does the problem still happen if you never start playback, ie. don't call BASS_ChannelPlay?

Please post the call stack from when you reproduce/catch the crash under the debugger.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #18 on: 24 Jul '23 - 16:20 »
Hey Ian, good to from you.

I will check that.

I am not a native English speaker, so I'm not sure what you mean by call stack. Can you give me a hint?


kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #20 on: 25 Jul '23 - 12:06 »
Actually when I don't use ChannelPlay it will already crash in the BASS_VST_GetInfo call.

If I do, it will actually work completely when I wait 30 seconds on every breakpoint (see screenshot code), but only Sometimes, otherwise the error occurs again.

Attached to this you can find the call stack, I hope you can find the information needed (I activated "Show external code").
« Last Edit: 25 Jul '23 - 12:18 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #21 on: 25 Jul '23 - 14:35 »
That call stack shows that the crash didn't happen in BASS or BASS_VST, but the source code shows it was just after a BASS_VST_GetInfo call, so perhaps that corrupted the stack or something. What was the exception message that came with the call stack?

If the crash happens within the BASS_VST_GetInfo call when you remove the BASS_ChannelPlay call, then please post the call stack and exception message from that case.

Please also check the size of "vstInfo", if possible. I'm not a VB.Net user myself, so I'm not sure, but I think you can check it like this: Len(vstInfo)

By the way, do you even need that "OKVM = New OKDialogViewModel" line where the crash was? There's already such a line at the start of the function. I'm guessing one of them is unnecessary?

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #22 on: 25 Jul '23 - 15:20 »
The error description is always the same, as I wrote in the first post. But I think "protected" can be better translated as "unmanaged". Unfortunately I could not find a proper translation, but it's definitely an AccessViolationException.

I tried again without ChannelPlay, and it also works sometimes, Sometimes not. But I still attached the call stack.

I tried to get the size of vstinfo in Bytes and it returned 304 with this:

System.Runtime.InteropServices.Marshal.SizeOf(vstinfo)

Gotta try that thing with OKVM, you might be right most likely...

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #23 on: 25 Jul '23 - 16:10 »
I forgot to say to make sure native code debugging is enabled in VS. Info on that here:

https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-in-mixed-mode?view=vs-2022
https://learn.microsoft.com/de-de/visualstudio/debugger/how-to-debug-in-mixed-mode?view=vs-2022

If that wasn't already enabled, please recheck the call stacks after enabling it.

kafffee

  • Posts: 252
Re: Issue with BassVst.BASS_VST_GetInfo
« Reply #24 on: 25 Jul '23 - 16:23 »
Is it nornal that it takes forever to execute the program when I activate native debugging? My VS 2022 just got frozen... And Task Manager displays that there are 16 instances of VS running...
« Last Edit: 25 Jul '23 - 16:37 by kafffee »