diff --git a/Engine/Collection/DrawnCollection.cs b/Engine/Collection/DrawnCollection.cs index 49d7a832..3cba85a6 100644 --- a/Engine/Collection/DrawnCollection.cs +++ b/Engine/Collection/DrawnCollection.cs @@ -5,6 +5,7 @@ namespace Altseed2 { internal class DrawnCollection { + public bool IsCollectionInForeach = false; private SortedDictionary> _Drawns; private SortedDictionary>> _Sorted; @@ -19,6 +20,7 @@ internal DrawnCollection() internal void Register(IDrawn node) { if (node == null) throw new ArgumentNullException(nameof(node)); + if (IsCollectionInForeach) throw new InvalidOperationException(); { if (!_Drawns.TryGetValue(node.ZOrder, out var set)) @@ -44,6 +46,7 @@ internal void Register(IDrawn node) internal void Unregister(IDrawn node) { if (node == null) throw new ArgumentNullException(nameof(node)); + if (IsCollectionInForeach) throw new InvalidOperationException(); _Drawns[node.ZOrder].Remove(node); @@ -60,6 +63,7 @@ internal void Unregister(IDrawn node) internal void UpdateCameraGroup(IDrawn node, ulong old) { if (node == null) throw new ArgumentNullException(nameof(node)); + if (IsCollectionInForeach) throw new InvalidOperationException(); for (int i = 0; i < Engine.MaxCameraGroupCount; i++) { @@ -87,6 +91,7 @@ internal void UpdateCameraGroup(IDrawn node, ulong old) internal void UpdateZOrder(IDrawn node, int old) { if (node == null) throw new ArgumentNullException(nameof(node)); + if (IsCollectionInForeach) throw new InvalidOperationException(); { _Drawns[old].Remove(node); diff --git a/Engine/Engine.cs b/Engine/Engine.cs index 93de5bb4..7a803687 100644 --- a/Engine/Engine.cs +++ b/Engine/Engine.cs @@ -184,7 +184,9 @@ internal static bool UpdateComponents(bool drawDefaultCameraGroup, bool drawCust if (drawDefaultCameraGroup) { // カメラが 1 つもない場合はデフォルトカメラを使用 + _DrawnCollection.IsCollectionInForeach = true; DrawCameraGroup(_DefaultCamera, _DrawnCollection.GetDrawns()); + _DrawnCollection.IsCollectionInForeach = false; } if (drawCustomCameraGroup) @@ -194,7 +196,9 @@ internal static bool UpdateComponents(bool drawDefaultCameraGroup, bool drawCust { foreach (var camera in _CameraNodes[i]) { + _DrawnCollection.IsCollectionInForeach = true; DrawCameraGroup(camera.RenderedCamera, _DrawnCollection[i]); + _DrawnCollection.IsCollectionInForeach = false; } } }