Search Issue Tracker
Fixed in 2021.2.X
Votes
0
Found in
Issue ID
1319358
Regression
No
NativeArray<T>.ReadOnly does not implement IEnumerable<T>
NativeArray<T> implements IEnumerable<T> allowing to use C# "foreach" syntax to iterate over it. However its read-only view (returned by calling .AsReadOnly()) does not, leading to an inconvenient inconsistency of the API.
This is especially problematic in some scenarios with DOTS.
In the attached project - and in particular in the attached screenshot -, there is a DOTS-based draft of a NBody physics system. The Job System prevents concurrent write access to the "velocityEntityChunks" array - at least in development mode - by raising an exception if I try to manipulate it directly. It forces me to call its readonly view by calling .AsReadOnly() before doing anything. For example it prevents line 39 to work via a runtime error.
My first reflex as a C# developer was to assume I could write the same "foreach" loop on the readonly view (as in line 43). However it does not compile because the type NativeArray<T>.Readonly returned by "AsReadOnly()" does not implement IEnumerable<T>. This forces me to rewrite the loop as in lines 47-50.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Buttons in the Overlay Menu in the Scene View are all gray even if they're activated when Game View is maximized and minimized
- NullReferenceException is thrown when baking Adaptive Probe Volume for a Terrain with Non-GI Contributing Tree Prototypes and multiple APV objects with different LayerMasks are present on the scene
- Hands are not recognized when using Hololens 2
- "OnTriggerExit2D" is called before "OnTriggerEnter2D" when object is destroyed immediately
- Editor crashes on PrepareSpriteTilingData when exiting Play mode
Resolution Note (fix version 2021.2):
Fixed in 2021.2.0a11