KeenSoftwareHouse / SpaceEngineers

2.94k stars 894 forks source link

Sandbox.Game.MyInventory.IsConnected(..) is not Thread safe #572

Open Dummy0815 opened 7 years ago

Dummy0815 commented 7 years ago

As the 'reachableVertices' list is declare as field the usage of this list inside IsConnected is not Thread safe. The list is only used inside the function and cleared before every usage, I suggest to use an local list instead. This will make the function Thread safe and will also reduce memory usage.

private bool IsConnected(MyInventory dstInventory) { var srcConveyor = (this.Owner as IMyConveyorEndpointBlock); if (srcConveyor != null) { var reachableVertices = new List<IMyConveyorEndpoint>(); MyGridConveyorSystem.FindReachable(srcConveyor.ConveyorEndpoint, reachableVertices, (vertex) => vertex.CubeBlock != null); foreach (var vertex in reachableVertices) { if (dstInventory.Owner == vertex.CubeBlock) { return true; } } } return false; }

ESearcy commented 7 years ago

Make a PR for it. with this as the desc. As long as the fix and need is clear/easy to make I'm sure they'd consider pulling it in.