SamOld
March 2, 2021, 11:09am
8
eizenhorn:
Unity using Roslyn’s compiler DisplayClass approach and has issues with scopes etc in Unity’s modification. Unity improving this and moving forward from display classes (as far as I know from chat with them about this topic last time in 2020). Issue here is that Roslyn generates two display classes (0_0 and 0_1) for this foo and bar and they both in a different one and both Job.WithCode writes to different DisplayClass and in case of second display class it writes foo into own DisplayClass.CS$<>8__locals1 and you might think “Hey why it’s not by reference its called Class” but it’s not. Both DisplayClass0_0 and DisplayClass0_1 are structs, and now you see that foo in DisplayClass.CS$<>8__locals1 it’s a copy, not reference and despite DisplayClasss-es itself passed with ref, CS$<>8__locals1 field not reference to DisplayClass0_0 but copy and Job changing this value of the foo to bar in DisplayClass0_1 , but it wouldn’t affect original DisplayClass0_0 from which you getting foo for Debug.Log.
I just realised that you already worked out and said pretty much everything that I worked out. Sorry! I had to go through it myself to fully get my head around it.
There’s probably some obvious reason why we can’t transform the references between the display structs into pointers, but I haven’t worked out what it is yet.