In Unity 2019.2 with burst 1.1.0+ I got following error (wan’t a problem in 2018.2)
Unexpected exception Burst.Compiler.IL.CompilerException: Error while verifying module: Global variable initializer type does not match global variable type!
[3 x float]* @“Unity.Mathematics.float3 Project.Common.Constants::f3_oneThousands”
Global variable initializer type does not match global variable type!
[3 x float]* @“Unity.Mathematics.float3 Project.Common.Constants::f3_halve”
at Burst.Compiler.IL.NativeCompiler.Compile () [0x00208] in <2e70f4489b014554927a1416135615fa>:0
at Burst.Compiler.IL.Jit.JitCompiler.CompileMethodInternal (Burst.Compiler.IL.Jit.JitCompiler+CachedMethodValue currentMethodValue, Mono.Cecil.MethodReference methodReference, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x002ce] in <2e70f4489b014554927a1416135615fa>:0
at Burst.Compiler.IL.Jit.JitCompiler.CompileMethod (Mono.Cecil.MethodReference methodReference, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x0006b] in <2e70f4489b014554927a1416135615fa>:0
at Burst.Compiler.IL.Jit.JitCompilerService.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job) [0x002ce] in <2e70f4489b014554927a1416135615fa>:0
While compiling job: System.Void Unity.Jobs.IJobExtensions/JobStruct`1<Project.ECS.Blocks.AddBlock2ConstructSystem/Job>::Execute(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
I have struct with
As I mentioned, it worked in burst jobs with Unity 2018.2.
How to fix it?
Edit:
I access variables directly in the job execute, rather than passing via Update to a job, like with other struct.
I just would like have them global, like constants.
I.e. I got
public const int i_hundred = 100 ;
But I can not have float3 as constant for example.
Oki, I will approach this problem with different question.
What would be best approach, to use global variables with burst / jobs?
Rom
August 4, 2019, 9:06pm
3
In the documentation here:
https://docs.unity3d.com/Manual/JobSystemTroubleshooting.html
It states that global variable access from jobs is prevented for safety reasons.
1 Like
Thx.
I see static (readonly) / constant data access has been changed, since Unity 2019.x.
Anyway, I modified these data accordingly yesterday.
As a workaround for now you can provide all x, y, z parameters in the static readonly constructor. That seems to work.
Thank you Joachim. That seams works nicely so far.
At least I don’t need pass constants via jobs boiler plates.
My simplified example.
static public class Constants
{
static readonly public float halve ;
// Auto load constants.
static Constants ()
{
halve = 0.5f ;
}
}
@Antypodish thank you for reporting this. For now you can use @Joachim_Ante_1 's workaround, and we’ll fix the bug in Burst in the next release.
1 Like
Thank you. Mostly appreciated for taking work on board.
Hey @Antypodish - thanks for finding this bug!
The bug is basically that our static readonly goes through a constant creation path that isn’t respecting the constructor of the float3. We’ll fix in a future burst version.
As a workaround for now you could do:
static public readonly float3 f3_halve = new float3 ( 0.5f, 0.5f, 0.5f ) ;
EG. initialize each field instead of relying on the float3 splat constructor.
Sorry for the inconvenience, but I’m on the fix!
2 Likes