[ModApi] MyVoxelGeometry.GetCellLineIntersectionOctree() is Not Thread-Safe
Not a Bug
Because a single overlap element cache list is used between all instances of MyVoxelGeometry and calls to GetCellLineIntersectionOctree(), voxel intersection checks cannot be safely multithreaded. This impacts (MyVoxelGeometry).Intersect(), both (MyVoxelBase).GetIntersectionWithLine() variants, and likely other methods as well.
Possible fixes would be to use an object pool (like is used elsewhere) or allow modders to supply their own cache list, but you (the poor developer reading this) would know better than I.
Example exception w/ stack:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at Sandbox.Engine.Voxels.MyVoxelGeometry.GetCellLineIntersectionOctree(Nullable`1& result, Line& modelSpaceLine, Nullable`1& minDistanceUntilNow, CellData cachedDataCell, IntersectionFlags flags) at Sandbox.Engine.Voxels.MyVoxelGeometry.Intersect(Line& localLine, MyIntersectionResultLineTriangle& result, IntersectionFlags flags) at Sandbox.Game.Entities.MyVoxelBase.GetIntersectionWithLine(LineD& worldLine, Nullable`1& t, IntersectionFlags flags)
Hello Aristeas,
Thank you for reaching our forum with this.
We have reproduced this issue on our side and put it into our internal system.
Kind Regards,
Keen Software House: QA Department
Hello Aristeas,
Thank you for reaching our forum with this.
We have reproduced this issue on our side and put it into our internal system.
Kind Regards,
Keen Software House: QA Department
Hello Aristeas,
After discussing this internally, we would like to confirm that MyVoxelGeometry.GetCellLineIntersectionOctree() is not thread-safe by design, and therefore it should not be called from multiple threads at the same time.
The reason is that making this path thread-safe would introduce significant performance overhead, and it is not required for normal game use. Because of this, we won’t be changing this behavior for now.
We will be closing this thread as 'Not a Bug' for now. And, we appreciate the time you’ve taken to report this issue. If you encounter any other issues, please feel free to create a new thread.
Thank you for your understanding.
Kind Regards,
Keen Software House: QA Department
Hello Aristeas,
After discussing this internally, we would like to confirm that MyVoxelGeometry.GetCellLineIntersectionOctree() is not thread-safe by design, and therefore it should not be called from multiple threads at the same time.
The reason is that making this path thread-safe would introduce significant performance overhead, and it is not required for normal game use. Because of this, we won’t be changing this behavior for now.
We will be closing this thread as 'Not a Bug' for now. And, we appreciate the time you’ve taken to report this issue. If you encounter any other issues, please feel free to create a new thread.
Thank you for your understanding.
Kind Regards,
Keen Software House: QA Department
Apologies, I'm not quite following; unless I've missed something, the only part of that path that isn't parallel-safe (at least for reads only) are parts writing to MyVoxelGeometry.m_overlapElementCache. Replacing this field with an object pool or making it thread-static should resolve the issue entirely with a negligible performance impact.
I understand that making it work properly with simultaneous voxel geometry edits is infeasible, but that's far easier to work around on the modder's side than not being able to call the method concurrently at all - this is a huge performance limitation (and source of exceptions that cannot be prevented) on what would otherwise be one of the better tools for getting voxel information.
Thank you for taking a look regardless,
Aristeas
Apologies, I'm not quite following; unless I've missed something, the only part of that path that isn't parallel-safe (at least for reads only) are parts writing to MyVoxelGeometry.m_overlapElementCache. Replacing this field with an object pool or making it thread-static should resolve the issue entirely with a negligible performance impact.
I understand that making it work properly with simultaneous voxel geometry edits is infeasible, but that's far easier to work around on the modder's side than not being able to call the method concurrently at all - this is a huge performance limitation (and source of exceptions that cannot be prevented) on what would otherwise be one of the better tools for getting voxel information.
Thank you for taking a look regardless,
Aristeas
Replies have been locked on this page!