obiwanjacobi / vst.net

Virtual Studio Technology (VST) for .NET. Plugins and Host applications.

Home Page:https://obiwanjacobi.github.io/vst.net/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unhandled exception from Jacobi.Vst.Host.Interop on ProcessReplacing

cuikp opened this issue · comments

When using Jacobi.Vst.Host.Interop from a .NET 5 host to interact with Effect-type VSTs (VST2), in some rare cases (only specific VSTs) calling ProcessReplacing crashes the managed host with an unhandled exception that is impossible to capture and handle from managed code (even the AppDomain.CurrentDomain.UnhandledException handler doesn't grab it) :

"An unhandled exception of type 'System.AccessViolationException' occurred in Jacobi.Vst.Host.Interop.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Or, with native code debugging on in Visual Studio:

"Exception thrown at 0x00007FFD0603993D (SynthMaster2FX.dll) in QuikDawEditor.exe: 0xC0000005: Access violation reading location 0x0000000000000054"

To Reproduce
Browsing the code I notice that ProcessReplacing is as follows:

float** ppInputs = inputs->Length == 0 ? _emptyAudio32 : _audioInputs.GetArray(inputs->Length);
float** ppOutputs = outputs->Length == 0 ? _emptyAudio32 : _audioOutputs.GetArray(outputs->Length);
int32_t inputSampleCount = CopyBufferPointers(ppInputs, inputs);
int32_t outputSampleCount = CopyBufferPointers(ppOutputs, outputs);
CallProcess32(ppInputs, ppOutputs, max(inputSampleCount, outputSampleCount));

(that is, without any error handling)

With all the numerous VSTs out there it would seem to be more trouble than it's worth to ferret out the specific cause of each error that a VST might be raising, but if the Vst.Host.Interop dll could simply handle any exceptions that are raised in this method (i.e not crash), it would allow the managed host program to grab the name of the VST so that it could just be ignored in the future.

  • OS: Windows 10
  • .NET Core 5.x

(In case it's useful to mention, the name of one VST that is raising the error is the free plugin "SynthMaster2FX.dll" by KV331 Audio)

By "impossible to capture and handle", I mean that the exception is not handleable by try/catch clauses, the WPF DispatcherUnhandledException handler or the AppDomain.CurrentDomain.UnhandledException handler, nor even by the AppDomain.CurrentDomain.FirstChanceException handler.