-
Notifications
You must be signed in to change notification settings - Fork 57
Example is not working properly #31
Copy link
Copy link
Open
Description
The ArrayDemo function in Example.Managed takes in a float[] on the C# side but is passed a NativeArray<float> on the native side. When marshalling this NativeArray to a C# array a bug happens, where the length gets set to 0 because Marshalling.MarshalArray() tries to call Marshalling.MarshalPointer() with ValueArrayContainer instead of ObjectArrayContainer, which is what actually maps to NativeArray(?).
ValueArrayContainer
{
public IntPtr Data;
public int Length;
}
ObjectArrayContainer
{
public IntPtr Data;
public IntPtr ArrayHandle;
public int Length;
}Coral::Array
{
...
private:
TValue* m_Ptr = nullptr;
TValue* m_ArrayHandle = nullptr;
int32_t m_Length = 0;
Bool32 m_IsDisposed = false;
}Seemingly even ObjectArrayContainer does not actually map to a NativeArray though.
Reproducing
This issue can be reproduced simply by compiling and running Example.Managed/Example.Native. Where the expected output would be something like:
[Coral](Info): Loading assembly 'C:\Users\jakhh\Documents\Code\c++\Coral\Build\Debug\Example.Managed.dll'
StaticMethod: 50
CustomAttribute: -2500
Example(50)
VectorAddIcall
X: 20, Y: 30, Z: 40
20
10
Hello, World?
NativeArrayIcall
5
0
10
50
ArrayReturnIcall
10
5000
1000
Whereas actual output is:
[Coral](Info): Loading assembly 'C:\Users\jakhh\Documents\Code\c++\Coral\Build\Debug\Example.Managed.dll'
StaticMethod: 50
CustomAttribute: -2500
Example(50)
VectorAddIcall
X: 20, Y: 30, Z: 40
20
10
Hello, World?
NativeArrayIcall
ArrayReturnIcall
10
5000
1000
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels