Closed renaudbedard closed 9 years ago
Minor, but testing Count does not guarantee that the count will be the same right after... TryDequeue should be just fine, it will return false if the queue's empty.
Looking at the .NET reference source (which upstream Mono now uses) it looks like the benefit of checking Count is lost now - even Count does some dirty work to check the actual count, unlike the older mscorlibs. So nnnnnnwhatevs!
https://github.com/flibitijibibo/FNA/commit/001e269924724e43d52750ee3d007b6911b1fc5d
The GL Object Disposal Wrapper methods of GLDevice (AddDisposeTexture, AddDisposeRenderbuffer, ...) use
Queue<T>
objects to store buffers to dispose if attempted to dispose on other threads, and in SwapBuffers(), FNA iterates over the queues to dispose them inline.It's possible (and I hit it a bunch of times in FEZ) that a queue gets added to and iterated/dequeued at the same time on two threads, which breaks the queue and a bunch of "null" elements appear in it.
This can be fixed by using
ConcurrentQueue<T>
, a lock-free concurrent queue implementation. Here's how I did it locally :And in SwapBuffers()...
The wrapper methods don't change since Enqueue() has the same API.