I have an array declared like this:
readonly static int[] triTable = new int[16 * 12]{ ... }
And a view on this array declared like this:
Span<int> triangulationInfo = new Span<int>(triTable, cellConfig * 12, 12);
Which generates the obscure error:
Burst internal compiler error: Burst.Compiler.IL.CompilerException: Error while verifying module: Invalid bitcast
%164 = bitcast <{ ptr, i32 }> %159 to ptr, !dbg !274
at Burst.Compiler.IL.NativeCompiler.Compile (Burst.Compiler.IL.CompilerStatistics stats) [0x004ca] in <74b8d24c73d245b5952c698ae125060a>:0
at Burst.Compiler.IL.Server.LibraryCompiler.HashAndCompileMethodGroup (Burst.Compiler.IL.Server.CompilationJob request, System.Int32 methodGroupIndex, Burst.Compiler.IL.Server.SharedLibraryCompilationState sharedState, Burst.Compiler.IL.Aot.AotCompilerOptions defaultOptions, Burst.Compiler.IL.NativeCompiler& nativeCompiler, Burst.Compiler.IL.Aot.AotModuleGroup& aotModuleGroup) [0x00570] in <74b8d24c73d245b5952c698ae125060a>:0
A workaround is to assign the array to the span and then slice it:
Span<int> triangulationInfo = triTable;
triangulationInfo.Slice(cellConfig * 12, 12);
Burst 1.8.16, Unity 2022.3.40f1
(the reason I’m using Span is simply because I can use the ref T operator[])