Hi, I need to get all building blocks in a certain distance with this code:
(Taken from BuildingGrades)
It works fine for small and medium sized bases.Code:List<BuildingBlock> Blocks = new List<BuildingBlock>(); Blocks.Add(StartBlock); Action<BuildingBlock> queue_attached_blocks = null; queue_attached_blocks = (Block) => { foreach(var collider in UnityEngine.Physics.OverlapSphere(Block.transform.position, 3.5f)) { var next_block = collider.GetComponentInParent<BuildingBlock>(); if(next_block == null || Blocks.Contains(next_block)) continue; queue_attached_blocks(next_block); } }; queue_attached_blocks(StartBlock);
But as soon as I try to loop through a very large base, i get a StackOverflowException.
Is it possible to increase the stack size somehow?
Or would anyone be able to help me to optimize this snippet?
StackOverflowException getting all building blocks
Discussion in 'Rust Development' started by Inofix, Oct 10, 2015.
-
Calytic Community Admin Community Mod
This looks like an infinite loop. The following code should be preventing an infinite loop.
But it's not preventing the loop because the following code is seemingly missing from inside the foreach statement..Code:if(next_block == null || Blocks.Contains(next_block)) continue;
Code:Blocks.Add(next_block)
-
Ah i pasted the wrong snippet, the other one is using !Blocks.Add(next_block)) continue; (HashMap)
