VL - Vector/Matrix from SharpDX resulting in exceptions

In the Gray Book, it says to use SharpDX.Mathetmatics types to have compatibility with VVVV Vectors and Matrices.

If I use SharpDX.Vector4, VL seems to read them fine, but I constant annoying errors like this:

If I use SharpDX.Mathematics.RawVector types, I seem to get the same errors. What’s up with this?

My code is extremely simple, just structs such as:

   public enum LightType
    {
        Point,
        Spot,
        Directional
    }


 [StructLayout(LayoutKind.Sequential)]
    public struct Light
    {
        public LightType LightType;
        public Color4 Colour;
        public float Intensity;
        public Matrix Transform;
        public Vector4 Params;

        public Light(LightType lightType, Color4 colour, float intensity, Matrix transform, Vector4 lightParams)
        {
            LightType = lightType;
            Colour = colour;
            Intensity = intensity;
            Transform = transform;
            Params = lightParams;
        }
    }

Here’s the full, unhelpful stack trace:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Cci.ReflectionEmitter.DynamicLoader.Emitter.EmitIL(ILGenerator ilGenerator, IMethodBody methodBody) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Microsoft.Cci\src\Microsoft.Cci.ReflectionEmitter\Emitter.cs:line 1320
   at Microsoft.Cci.ReflectionEmitter.DynamicLoader.Emitter.Visit(IMethodDefinition method) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Microsoft.Cci\src\Microsoft.Cci.ReflectionEmitter\Emitter.cs:line 991
   at Microsoft.Cci.MetadataTraverser.Traverse(IMethodDefinition method)
   at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 methods)
   at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition)
   at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition)
   at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 types)
   at Microsoft.Cci.ReflectionEmitter.DynamicLoader.Load(IEnumerable`1 types) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Microsoft.Cci\src\Microsoft.Cci.ReflectionEmitter\Emitter.cs:line 180
   at VL.Lang.Platforms.CIL.CilCompilation.CreateDynamicLoader(CancellationToken token) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Lang\src\Platforms\CIL\Lazy\Compilation.cs:line 547
   at VL.Lang.Platforms.CIL.CilCompilation..ctor(Platform platform, PreCompilation compilation, CompilationOptions options, CancellationToken token, ImmutableHashSet`1 entryPointIds, CilCompilation previous, String exportDir) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Lang\src\Platforms\CIL\Lazy\Compilation.cs:line 103
   at VL.Lang.Platforms.CIL.CilCompilation.WithCompilation(PreCompilation compilation, ImmutableHashSet`1 entryPointIds, CancellationToken token) in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Lang\src\Platforms\CIL\Lazy\Compilation.cs:line 621
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VL.Lang.Platforms.CIL.Platform.<UpdateAsync>d__30.MoveNext() in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Lang\src\Platforms\CIL\Platform.cs:line 176
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at VL.Lang.Platforms.CIL.Platform.<Session_CompilationUpdated>d__29.MoveNext() in C:\BuildAgent\work\95074898639d5736\vvvv50\VL.Lang\src\Platforms\CIL\Platform.cs:line 157
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
VVVV.Hosting
    Assembly Version: 0.0.0.0
    Win32 Version: 38.1.4003.0
    CodeBase: file:///D:/dev/vvvv_50beta38.1_x64/lib/core/VVVV.Hosting.DLL
----------------------------------------
VVVV.PluginInterfaces
    Assembly Version: 0.0.0.0
    Win32 Version: 38.1.4003.0
    CodeBase: file:///D:/dev/vvvv_50beta38.1_x64/lib/core/VVVV.PluginInterfaces.DLL
----------------------------------------
VVVV.Core
    Assembly Version: 0.0.0.0
    Win32 Version: 38.1.4003.0
    CodeBase: file:///D:/dev/vvvv_50beta38.1_x64/lib/core/VVVV.Core.DLL
----------------------------------------
System.Drawing

Hi @polyrhythm,
Looking at your patch I see that the LightType isn’t linked to anything, and therefore is receiving Null.

There are a few ways around this, one of which is to create a default version of your type so the system can apply that when it doesn’t see anything else.
Check here and search for ‘create default’ on the page.

Otherwise, you can work paused until these things are all connected up (F6, and press F5 to be back running live again).

Thanks! I’ll fix it up using your advice. I suppose that while in VL I’ll have to program more defensively because of the nature of everything being evaluated every frame.

the native VL types are SharpDX.Mathematics Vector2/3/4 and Matrix with SharpDX version 4.0.1. maybe you are using SharpDX 4.2?

but as Guest said, if you don’t provide and instance to the input of your member operation you might get a null exception.

As tonfilm said check the SharpDX version you’re compiling against - must be 4.0.1 - also would be good to know what version of vvvv you’re using and if possible zip the whole thing you have to give us a chance to look at it and find ways to prevent exceptions like you see. They’re not related to the LightType being null as it happens much earlier when VL tries to emit the IL code.

Switching to 4.0.1 seemed to fix my issue, but if you’re curious how to replicate, it’s very easy - just create a VL node that tries to use a SharpDX 4.2 type.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.