This site requires JavaScript, please enable it in your browser!
Greenfoot back
danpost
danpost wrote ...

2012/3/18

Altering stack space

danpost danpost

2012/3/18

#
Need step-by-step on increasing stack space for a specific Greenfoot scenario (Equation Grapher). Using: Greenfoot version 2.1.2 (Java version 1.6.0_27) Java HotSpot(TM) Client VM 20.2-b06 (Sun Microsystems Inc.) Windows 7 6.1 (x86) OR - should I upload source, so it can be checked to see if that is what I need to do?
davmac davmac

2012/3/18

#
Why do you need to do that? (at least: why do you think you need to do that?)
danpost danpost

2012/3/18

#
I am getting stack overflow errors in my 'Equation Grapher' scenario when I enter long or complicated equations. An example equation is: (abs(x)^x)^(abs(x)^x) It computes maybe 25 to 30 percent of the 800 points, and then bombs out. The program does have recursive calls; meaning: (1) plot calls evalFormula (2) evalFormula calls evalTerm (3) evalTerm calls evalFactor (4) evalFactor may recall evalFormula (possibly once for the body of the factor, and possibly once again, if an exponent is present)
davmac davmac

2012/3/18

#
Most likely cause is that you have a bug resulting in infinite recursion, hence the stack overflow. The default stack should be enough for a reasonably amount of recursion. If you upload the source I'll have a quick look.
danpost danpost

2012/3/18

#
Source uploaded with scenario, you can un-comment the terminal print-out lines in the Graph class, and see what I was talking about.
davmac davmac

2012/3/18

#
When I uncomment the lines in evalFormula(...), I see the following output: Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ ... So, definitely infinite recursion! Right at the start I see: Formula is: (abs(x)^x)^(abs(x)^x) Formula is: abs(x)^x Formula is: x Formula evaluated to: -4.0 Formula is: x Formula evaluated to: -4.0 Formula evaluated to: 0.00390625 Formula is: x)^ Formula is: x)^ Formula is: x)^ Formula is: x)^ ... So the first part works but then at some stage the formula is "x)^" and at that point it goes wrong. I'll leave this to you to debug! Increasing the stack size definitely won't help.
danpost danpost

2012/3/18

#
Thanks for looking into it. I will see what I can find.
danpost danpost

2012/3/18

#
@davmac, thanks again! I did find the problem. Actually, there were two (related). (1) I had a 'while' where there should have been an 'if' (when removing paired parenthesis) (2) needed an 'else' after that same 'if' statement The location was in the 'evalFactor' method of the 'Graph' class. You can change that in your copy to have a corrected one. The 'while' statement was immediately before the 'if (isFunction(factor))' statement.
You need to login to post a reply.