Deep recursion in RecipeHelper.generateMaterialListTuples()
VADemon opened this issue · 9 comments
Over 700 recursive calls deep and it'll crash under -Xss256k
. The function should be reconsidered or rewritten. Maybe in the overhaul of NC since that's what you're planning :) Just keep that in mind then.
Oracle JDK 8, MC 1.12.2, FTB Revelations 3.2.0
@VADemon You'll have to excuse my inexperience with programming in general for this question, but would using some iterative procedure rather than a recursive one avoid the stack overflow issue?
Not OP but yes, the stack overflow happens because each time you make a call into a function a new stack frame is created. It's part of what gives you that handy stack trace that lists all the function calls in the stack that led to an exception. If the number of stack frames gets too big it can overflow. Using an iterative method will prevent this.
Edit:
From https://www.artima.com/insidejvm/ed2/jvm2.html :
The Java stack is composed of stack frames (or frames). A stack frame contains the state of one Java method invocation. When a thread invokes a method, the Java virtual machine pushes a new frame onto that thread's Java stack. When the method completes, the virtual machine pops and discards the frame for that method.
Right, so recursion, although handy, piles up a large number of frames, which then all get taken off sequentially, while iteration is a process of pushing and pulling to/from the stack one at a time.
Should be able to sort this - might be worth fixing it for both the new builds and the old ones :)
@VADemon (and @Andrew-Rominger if you're having the same issue), I have a new build here which I think should fix the issue - could you give it a run with your Revelations instance? If it works, I'll put the build up on CF ;)
I think it has become worse: iirc it ran with -Xss320k
before, but now it needs ~ -Xss384k
and the crash log shows 1026 lines upon StackOverflow.
PS: Looks like MC needs a bare minimum of -Xss192k
to initialise (otherwise crashes somewhere in natives of LWJGL)
PPS: You shouldn't commit "versions", commit changes when using git. To publish a "version" use tags and Github's releases for compiled binaries. You bundle too many changes in a single commit, can't easily revert a single feature change this way.
PPPS: Yeah, btw it's still a low priority problem, just try to not make it worse than it was before ;)
@VADemon I'm not using Git properly - it's just a repository for people to look at the source code; I'm happy to just deal with changes locally :)
As for why it was worse than before, turns out I literally forgot to remove the recursive call, so that was happening as well as the iterative one... soz about that :P
Now hopefully this build should work!
Huzzah! Thanks very much for your help and patience :P
Will get a build out shortly ;)