I’m using a recursive function in my pathfinder, and I ran into a recursion depth exceeded error. I know how to fix it, but it made me curious. How many recursions is too many? What is the depth limit?
Hm, that usually indicates you have a never-ending loop there. You can disable the recursion limit, but that’s really not recommended. If you disable it, you’ll probably get a hard-crash when your stack overflows.
It’s a recursive function that runs through an a* algorithm, that had more around 7000 nodes and could have run into paths 1000s of nodes long, so I’m pretty confident I could have reached the recursion limit without an infinite loop. I’ve dropped it down to about 1600 nodes now which should clear up the problem. I was more interested in knowing what the depth limit was to satisfy my own curiosity.
from sys import getrecursionlimit getrecursionlimit ()
in my case it was 1000
a-star doesnt has to be recursive, using the usual approach using open-closed lists makes it quite easy. i would highly recommend using this method, because you will likely hit the recursion limit depending on the terrain size. also it’s probably more memory efficient if you dont use recursion.
the wikipedia entry even has a pseudocode that illustrates the method i recommend:
I can’t believe that the idea of not using recursion never occurred to me before. The recursion is easily replaced by a while loop. I feel like such an idiot now.