Description
Hello again :)
This time I'm having trouble with some functions crashing Unity, and having a hard time nailing down the cause... I was hoping you could help me figure it out.
This is the code I use (can be pasted directly into the sample .cpp file):
Transform t(go.GetTransform());
t.GetLocalToWorldMatrix(); // crash
Matrix4x4::GetIdentity(); // crash
t.GetPosition(); // ok
String layerName("Default");
LayerMask::NameToLayer(layerName); // crash
Oh, and the relevant NativeScriptTypes.json, if that helps:
{
"Name": "UnityEngine.LayerMask",
"Methods": [
{
"Name": "NameToLayer",
"ParamTypes": [
"System.String"
]
}
]
},
{
"Name": "UnityEngine.Transform",
"Properties": [
{
"Name": "position",
"Get": {},
"Set": {
"Exceptions": [
"System.NullReferenceException"
]
}
},
{
"Name": "worldToLocalMatrix",
"Get": {}
},
{
"Name": "localToWorldMatrix",
"Get": {}
}
]
}
I attached a debugger to the Unity Editor, and it doesn't say much (Access violation reading location 0x0, when calling Plugin::UnityEngineTransformPropertyGetLocalToWorldMatrix(Handle);
in the generated bindings). Happens on both Unity 2017 and 2018, on both Debug and Release build, on Windows.
Those methods are pretty straightforward. GetPosition and GetLocalToWorldMatrix are almost identical when decompiling UnityEngine.dll - they are just calls to native code. I thought it might be because it's returning a Matrix4x4, but LayerMask::NameToLayer
crashes too and it's only returning an int...
Out of curiosity, I tried moving those calls to a C# script, then call the C# script from the C++ code - the result was the same.