You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MarshalDirectiveException: cannot marshal type System.Single[,] for Android/Oculus #65
When built as an APK (Oculus Pro), the SimpleInletScaleObject.cs script throws an error: MarshalDirectiveException: cannot marshal type System.Single[,].
It works fine in the editor as well as PC VR, but standalone version will cause the issue.
I've narrowed it down to SimpleInletScaleObject.cs, Line 35: uint res = dll.lsl_pull_chunk_f(inlet.obj, data_buffer, timestamp_buffer, (uint)data_buffer.Length, (uint)timestamp_buffer.Length, timeout, ref ec);
The same occurs for the other sample scenes provided by LSL's samples (as of 1.16.0)
I assume this may be more of an issue with Android, but I thought it would be good to bring it to your attention, just in case.
I have created a workaround.
I essentially flatten the 2D array into a 1D array.
I changed SimpleInletScaleObject.cs, so that instead of it saying data_buffer = new float[buf_samples, n_channels];
it instead says: data_buffer_flat = new float[buf_samples * n_channels];
using a new float[] data_buffer_flat variable.
I then edited LSL.cs at line 640, (the pull_chunk variable that uses float[,])
public int pull_chunk(float[,] data_buffer, double[] timestamp_buffer, double timeout = 0.0)
{
int ec = 0;
int numRows = data_buffer.GetLength(0);
int numCols = data_buffer.GetLength(1);
float[] data_buffer_flat = new float[numRows * numCols];
for (int i = 0; i < numRows; i++)
{
for (int j = 0; j < numCols; j++)
{
data_buffer_flat[i * numCols + j] = data_buffer[i, j];
}
}
uint res = dll.lsl_pull_chunk_f(obj, data_buffer_flat, timestamp_buffer, (uint)data_buffer_flat.Length, (uint)timestamp_buffer.Length, timeout, ref ec);
LSL.check_error(ec);
// Unflatten the data_buffer_flat back into data_buffer
for (int i = 0; i < numRows; i++)
{
for (int j = 0; j < numCols; j++)
{
data_buffer[i, j] = data_buffer_flat[i * numCols + j];
}
}
return (int)res / numCols;
}
LSL.cs had the function "lsl_pull_chunk_f" edited as well at line 1115:
This has fixed the error with marshaling/sending data that uses [,] to Android/Oculus, while being sure to convert it back to a 2D array for Unity to handle.
This only works for floats[,] but doing it to the int[,] and double[,], etc should be similar.
It still works in the Editor and on Windows as well.
I ran into the same issue with a Windows build when the scripting backend is set to IL2CPP. With Mono, it works fine.
Tested on Unity 6000.2.9f1, Windows 10.
Another potential workaround is to pull samples instead of chunks.
Activity
JustinHornsby commentedon May 21, 2024
I have created a workaround.
I essentially flatten the 2D array into a 1D array.
I changed SimpleInletScaleObject.cs, so that instead of it saying
data_buffer = new float[buf_samples, n_channels];it instead says:
data_buffer_flat = new float[buf_samples * n_channels];using a new
float[] data_buffer_flatvariable.I then edited LSL.cs at line 640, (the pull_chunk variable that uses float[,])
LSL.cs had the function "lsl_pull_chunk_f" edited as well at line 1115:
This has fixed the error with marshaling/sending data that uses [,] to Android/Oculus, while being sure to convert it back to a 2D array for Unity to handle.
This only works for floats[,] but doing it to the int[,] and double[,], etc should be similar.
It still works in the Editor and on Windows as well.
I uploaded as a .txt file if anyone wants to take a look at them.
LSL.txt
SimpleInletScaleObject.txt
zcha621 commentedon Jul 5, 2024
I also had this problem.

erikvdb commentedon Oct 29, 2025
I ran into the same issue with a Windows build when the scripting backend is set to IL2CPP. With Mono, it works fine.
Tested on Unity 6000.2.9f1, Windows 10.
Another potential workaround is to pull samples instead of chunks.