Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
Jeffen Nilsson
118 discussion posts
Displayfusion Version: 11.0 (Beta 2)
Windows 11

i've been messing around today trying to create a script that will change my BUS mode in voicemeeter depending on a trigger in displayfusion.

Running the script in VSC there is no issues at all, the bus mode is changed when the script is ran.

It becomes an issue when i try to run it in displayfusion though.
It successfully verifies and then runs as it should.

However when i try to run the script a second time displayfusion completely crashes with no pop-up errors or apparent errors in the troubleshooting log.

Here is my code:

Code

using System;
using System.Runtime.InteropServices;

class DisplayFusionFunction
{
    // Import the VoicemeeterRemote64.dll functions
    [DllImport("C:\\Program Files (x86)\\VB\\Voicemeeter\\VoicemeeterRemote64.dll")]
    public static extern int VBVMR_Login();

    [DllImport("C:\\Program Files (x86)\\VB\\Voicemeeter\\VoicemeeterRemote64.dll")]
    public static extern int VBVMR_Logout();

    [DllImport("C:\\Program Files (x86)\\VB\\Voicemeeter\\VoicemeeterRemote64.dll")]
    public static extern int VBVMR_SetParameterFloat(string szParamName, float value);

    public static void Run()
    {
        VBVMR_Login();
        VBVMR_SetParameterFloat("Bus[0].mode.TVMix", 1.0f); // Bus A1
        BFS.General.ThreadWait(1000); // Must sleep before logout otherwise the change is intermittent.
        VBVMR_Logout();            
    }
}


I have another script which is the same other than the bus mode is "normal" instead of "TVMix".
It doesn't matter if i run these script alternatively or just the same script back to back, it always crashes displayfusion.

not sure if i am doing something wrong in this script or if there is something wrong with displayfusion for just straight up crashing without any error messages.

I have the api documentation here: https://download.vb-audio.com/Download_CABLE/VoicemeeterRemoteAPI.pdf if that helps
Jan 14, 2024 (modified Jan 14, 2024)  • #1
User Image
JLJTGR
104 discussion posts
Knowing very little about the library you're using... since it is unmanaged code, I wonder if there is some resource you're not releasing in your script that crashes when you attempt to access it twice. It's obviously the unmanaged code that is causing the crash here, so the managed code context is probably not understanding the error that is happening.

Since the last couple Windows versions, Microsoft would rather silently crash programs instead of telling the user something bad happened. I don't know why. Anyways, check the Event Viewer, Application Log. It will likely say something about DisplayFusion crashing with the faulting assembly being in your unmanaged library. Unfortunately, you probably won't be able to get a good error message out of it... but there's a small chance the hex error code will make sense if you look it up in
https://www.hresult.info/
or something.
Jan 14, 2024  • #2
User Image
Jeffen Nilsson
118 discussion posts
I'm getting 2 separate errors in the event viewer:

Code

Application: DisplayFusion.exe
CoreCLR Version: 8.0.123.58001
.NET Version: 8.0.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Stack:
   at DisplayFusionFunction.VBVMR_SetParameterFloat(System.String, Single)
   at DisplayFusionFunction.VBVMR_SetParameterFloat(System.String, Single)
   at DisplayFusionFunction.Run()
   at DynamicClass.InvokeStub_DisplayFusionFunction.Run(System.Object, System.Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(System.Object, System.Reflection.BindingFlags)
   at WbhP.DbhC.Run(jb4x, System.Type, System.Object, System.String, O2EW.p2E9, System.Object ByRef)
   at abwI.ybwL.RunCodeTHREAD(D27z.q27j, jb4x, WbhP.DbhC, System.Type, System.Object, System.String, kb4T, MTo3)
   at abwI.ybwL+<>c__DisplayClass0_0.<RunFunction>b__0()
   at CxON.JxOq+<>c__DisplayClass28_0.<.ctor>b__1()
   at System.Runtime.ControlledExecution.Run(System.Action, System.Threading.CancellationToken)
   at CxON.JxOq+<>c__DisplayClass28_0.<.ctor>b__0()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)


And:

Code

Faulting application name: DisplayFusion.exe, version: 10.99.99.102, time stamp: 0x65680000
Faulting module name: coreclr.dll, version: 8.0.123.58001, time stamp: 0x65684720
Exception code: 0xc0000005
Fault offset: 0x00000000001bf0cc
Faulting process ID: 0x0xF24
Faulting application start time: 0x0x1DA46DC2A59D116
Faulting application path: C:\Program Files\DisplayFusion\DisplayFusion.exe
Faulting module path: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.1\coreclr.dll
Report ID: 69e5face-f2e2-4b04-8bed-24c5693620da
Faulting package full name: 
Faulting package-relative application ID:


From the website you gave me the application error (0xc0000005) points to "Invalid access to memory location", and then the .NET error points to "Attempted to read or write protected memory".

So not sure exactly what that means or what the remedy is.

If its unmanaged code i can't really find out what i need to change since the only explicitly called out code in the docs is VBVMR_Logout() at the end of the program which is what i have.
And since it ran without errors in visual studio code and the built .exe's work fine as well, i thought it would have something to do specifically with displayfusion - but maybe not.

I tried removing the whole block in the main method and ran the function - no issues.
but when i added just

Code

VBVMR_Login();
VBVMR_Logout();
it will crash.

gonna keep testing.

Weirdly enough removing

Code

VBVMR_Logout();
from the code seems to just run fine with no crashing at all...
Not sure if that is going to cause any issues going forwards but until then it works for now.

Quote:
IMPORTANT REM: Call VBVMR_Logout() once at the end of the program.
:|
Jan 14, 2024 (modified Jan 14, 2024)  • #3
User Image
JLJTGR
104 discussion posts
Well, the stacktrace of the crash says that VBVMR_SetParameterFloat() was the problem rather than login/logout. Briefly looking through the document, it says that the login lasts the lifetime of the execution. Since DisplayFusion does not close between script executions nor does it tear down the AppDomain the code is running in, there is only one "lifetime". It's possible you should only login once and somehow something stays in memory.

If your test applications only do their operation once and then close, that doesn't really test this scenario. Their lifetime gets reset by closing and running again. If you make your test program do the same operation several times in a row, that would be a better test to similate this.
Jan 14, 2024  • #4
User Image
Jeffen Nilsson
118 discussion posts
Quote:
Well, the stacktrace of the crash says that VBVMR_SetParameterFloat() was the problem rather than login/logout. Briefly looking through the document, it says that the login lasts the lifetime of the execution. Since DisplayFusion does not close between script executions nor does it tear down the AppDomain the code is running in, there is only one "lifetime". It's possible you should only login once and somehow something stays in memory.

If your test applications only do their operation once and then close, that doesn't really test this scenario. Their lifetime gets reset by closing and running again. If you make your test program do the same operation several times in a row, that would be a better test to similate this.


That appears to have done the trick.

I have a trigger to login when displayfusion starts and then a trigger to logout when displayfusion exits.
Then a trigger for just the bus mode switch depending on the focused application.

unless i'm missing something that should now work fine :)

Thanks for the help!
Jan 14, 2024  • #5
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)