#How can I log those values
1 messages · Page 1 of 1 (latest)
NativeArray<float> floatArray = new NativeArray<float>(16, Allocator.Temp);
FieldInfo[] fields = floatArray.GetType().GetFields(
BindingFlags.NonPublic |
BindingFlags.Instance);
FieldInfo lengthFieldInfo = default;
FieldInfo minIndexFieldInfo = default;
FieldInfo maxIndexFieldInfo = default;
foreach (var fieldInfo in fields)
{
if (fieldInfo.Name == "m_Length")
lengthFieldInfo = fieldInfo;
if (fieldInfo.Name == "m_MinIndex")
minIndexFieldInfo = fieldInfo;
if (fieldInfo.Name == "m_MaxIndex")
maxIndexFieldInfo = fieldInfo;
}
var length = lengthFieldInfo.GetValue(floatArray);
var minIndex = minIndexFieldInfo.GetValue(floatArray);
var maxIndex = maxIndexFieldInfo.GetValue(floatArray);
This is how you'd do it outside of burst. (Only do this kind of thing to debug or for educational purposes, never in production)
You can also do a similar thing inside of burst, but it'd use unsafe code, I'll share how in a moment.
Mmm, the bug only appears on burst and it's not persistent
But i was thinking too of reflection, but I'm calling that method A LOT
And it doesn't happen otherwise either
Do you know of any way to stop recompilation of burst?
Im thinking that that is what is breaking it. It's too inconsistent
unsafe
{
NativeArray<float> floatArray = new NativeArray<float>(16, Allocator.Temp);
void* addressToStructItself = UnsafeUtility.AddressOf(ref floatArray);
ref int length = ref UnsafeUtility.AsRef<int>(((byte*)addressToStructItself) + sizeof(void*));
ref int minIndex = ref UnsafeUtility.AsRef<int>(((byte*)addressToStructItself) + sizeof(void*) + sizeof(int));
ref int maxIndex = ref UnsafeUtility.AsRef<int>(((byte*)addressToStructItself) + sizeof(void*) + sizeof(int) + sizeof(int));
}
This is how you get the values in burst compiled code. It's ugly, but will help you debug.
Note that minIndex & maxIndex get set when scheduling ParallelForJobs, those jobs allow you to work on a single nativearray on multiple threads, but they set the minIndex & maxIndex as some form of safety to prevent different threads from reading/writing to the same data.
But I'd expect a different exception message if you'd be breaking the ParallelForJob restriction.
Anyway, logging the values should bring you one step closer to the solution.
What version of Burst & Entities are you using?