Hi,
You are removing elements from Exit List
while iterating over it.
That needs to be done in multiple passes (top level loops), typically you identify things in first pass, remove in second. That doesn’t seem to fit your use case, so you might need a more radical restructure:
While list not empty:
Pop first thing off it.
Loop over the remainder finding overlaps and recording results (do not act on them in this loop).
Loop over your result list/map/whatever and act on everything identified before, and remove things from the exit list.
Whatever you do, do not remove from an array while you are iterating over it! There be dragons.