Hi,
I’m using Unity 5.6.0xf3 Linux. I have this code :
var co = existingChanges.Count;
var en = existingChanges.GetEnumerator();
for (int i = 0; i < co; i++)
{
en.MoveNext();
changesA[i] = en.Current.Value;
changeIndicesA[i] = en.Current.Key;
}
en.Dispose();
existingChanges.Clear();
The ‘existingChanges’ variable is a Dictionary that gets filled and cleared each frame, and can sometimes become really big.
The problem is, as long as it’s not empty, sooner or later this error pops up :
where InstanceRenderer.cs:85 is en.MoveNext();
This problem hasn’t happened in the past, and I don’t know how to fix it. I originally used LINQ on my dictionary and it threw up weird exceptions too.
My code runs entirely on 1 thread (apart from compute shader calls, which I think work on a separate thread) .
So as a self-stupidity check, do you think this might be a bug ( I’m suspecting GC ) or am I just missing something glaringly obvious?
The class is named InstanceRenderJob, and looks like it’s running in a compute shader? Is this perhaps happening in a multi-threaded context? That would cause an out of sync real fast.
I was hoping to use multithreading in the long run, but for now I do not, and this part of the code should definitely be single threaded. The exception occurs both in the editor and in standalone, so editor related scripts are out of the question too.
EDIT:
The resulting arrays are fed into buffers for compute shaders at a later step, this should be independent from the dictionary though.
Solved it, it was indeed sheer stupidity on my part. The GC runs on a separate thread and I had destructors that , in a very convoluted way, accessed the dictionary -_- . 8h of work to find it, because I believed I couldn’t have made a mistake facepalm
I solved it via locking the offending functions over the dictionary. Forcing the GC is too expensive.