Search code examples
c#.netlistrecursionstack-overflow

What crashes Unity3D, recursion or a huge generics list?


I am working with Unity3D package

Using a code which has 2 areas of interest, one of which probably causes a stack overflow and makes unity to throw a submit bug error.

1) Either a recursion which reaches 800 levels (works perfect with 600, starts to struggle at 700) as it traverses down the node-web, searching for unexplored children of those nodes. When it finds a dead end - it copy-pastes the path that lead towards this dead end into a list. Each node has about 10 children

2) Or , as a result - huge lists carrying paths in other list, example 58 000 cells full of other lists (on top of that - procedure is done for every node in the scene).

a) I though that it might have been a recursion, that I need to translate it into a stack form, but now I am more and more inclined to think that this because of the huge lists. Should I split my list into smaller ones? Can I do something to avoid this stack overflow, if it is one?

b) With that, could you please explain if list size matter for stack and can they overflow it?

I got 8 GB of RAM, but resource manager said Unity only uses 1.5GB before it crashes

Please advise!

Thank you very much!


Solution

  • Having re-structured my pile of code, biting out those lists, leaving out empty spaces instead, the problem still persisted, so it is indeed, a recursion.

    Everybody who is interested further on, please follow here for a recursion-to-stack conversion, taking into account Path to each of the dead-ends of the web a recursion had to go through.