Kinematica: Demo - Null Exceptions when clicking character and hovering inspector

Hi, just wanted to notify this bug, which also triggers when enabling/disabling an ability (related post last month). Something with the ledge object?

It happens when clicking the character on the hierarchy, and then continuously when hovering the inspector with the character selected. Attaching image.

Thanks, Aitor

6601111--750640--ErrorLog.PNG

Thanks for the info! Would you be able to report a bug using Unity's bug reporting window? Help->Report a bug..

1 Like

I noticed this issue as well, and did some digging to see what the cause was. It looks like the problem comes from SnapshotProviderEditor trying to calculate the snapshot size of ClimbingAbility.ledgeGeometry when not in play mode. Internally, the LedgeGeometry struct contains NativeArray field tracking the vertices of the ledge, but it is only initialized at runtime. So in the editor we get an error logged because trying to read the uninitialized NativeArray trips a safety check.

As far as I can tell this isn't strictly a bug in Kinematica itself. For the demo, you can fix this updating LedgeGeometry.WriteToStream() (ClimbingAbility.Ledge.cs line 238) and adding a check against NativeArray.IsCreated so that it won't try to read the vertices array if it's not initialized:

if (vertices.IsCreated)
{
    buffer.WriteNativeArray(vertices, Allocator.Persistent);
}

For any projects trying to use Kinematica, you'll only run into this error if you are doing something similar where you have a NativeArray inside of a type that you want to track via the snapshot inspector, and you can avoid the error with a similar approach.

That said, I do wonder if the WriteExtensions.WriteNativeArray() that's being used in that function shouldn't be updated to check array.IsCreated in order to better handle this sort of case. I don't know know if the expectation is that WriteNativeArray() should only be called with an initialized array, and therefore it's on the caller to check IsCreated, but if not this could possibly be a place where Kinematica could be updated.

@grahamsaulnier I can submit an official bug report if it still makes sense to do so, though given that Kinematica's development has been put on hold for the duration of 2021 I imagine it doesn't matter much at this point. If nothing else, I figure posting this information might save a Kinematica dev an hour of debugging when they do eventually return to it :smile:

2 Likes