Avoid instance method invocation if there is no instance

Hi, digging on NURBS library, and noticed something that seems to need some polishing on vl side.

So I have a C# struct, that manages native memory:

public record struct NurbsCurve
{
        // some properties
   
        // instance method
        public float GetParamByLength(float length)
        {
            return (float)
                LNLibNurbsCurve.GetParamByLength(
                    NativeCurve,
                    length,
                    IntegratorType.INTEGRATOR_GAUSS_LEGENDRE
                );
        }
}

So, when I add this method from node browser, I get an instant crash, since it tries to use unassigned native memory… Normally you get just an exception that instance was null but in this case vvvv is gone… I’m adding some safety checks obviously. However if I define Class in vl, and try to add method to patch witch is disconnected from instance I don’t have error.

The question is:

Can this be resolved on VL side of things, or maybe C# declaration can be decorated with something?

For classes, you get a null exception, but this is a record, so the memory will always be created. In this case, struct might not be the right data type, as you probably want to pass around a reference to the curve and not copy around the memory all the time.

Well I made it this way, so you can cleanly see, when it’s changed by something. But class vs struct seems to be out of scope of this particular request, if u want to joint efforts, be my guest at GitHub - antokhio/VL.LNLib: A NURBS, Bezier library for vvvv based on LNLib by BIMCoderLiang

I would gladly appreciate some guidance and advices, since this thing is quite complex and I’m not that much in to NURBS topic.

Basically for nurbs curve I’m about to 2-3% of whole API

Maybe give a class-based record a try. This way you should be able to combine the immutability feature with the reference feature.

ROFL, it seem issue I was bumping was just a peak of iceberg, it seems the actual problem I have is that underlying lib throws access violations even if it’s fed with correct parameters, making the whole thing kind of unstable…

Guess I will have to abandon current state and take route to port that thing from scratch, the performance vise when you start to feed it with realtime parameters seems to be also quite slow…