CLOSED: too much recursion

Bugs will be moved here once resolved.

Post » Tue May 14, 2013 12:30 am

Link to .capx file (required!):
https://dl.dropboxusercontent.com/u/28087823/Construct%20Examples/recursionBug/recursionbug.capx

It's a simple test of recursion, it ought to calculate the sum of all integers up to the value I put into the function call parameter0

Steps to reproduce:
1. run the layout
2. press the calculate button
3.

Observed result:
About half the times, for values over 40 in the function call, it gives me this message:

*Javascript error!
too much recursion
http://localhost:50000/Function_plugin.js, line 192 (col undefined)

This is either a bug in Construct 2 or a problem in a third party plugin or behavior - please report it to the developer"

If I press the "calculate" button again, it DOES provide the correct calculation

Expected result:

It should provide the correct calculation without first giving me an error message.

Browsers affected:
Chrome: yes ( for values over 1000 )
Firefox: yes (for values over 40)
Internet Explorer: ?

Operating system & service pack:
windows 7

Construct 2 version:
128.2 (32bit)christina2013-05-14 13:38:55
B
19
S
6
G
2
Posts: 188
Reputation: 2,744

Post » Tue May 14, 2013 1:10 pm

Closing - despite the error message, this is not a bug in Construct 2. In all programming languages you cannot recurse too deep or you overflow the stack. For example with a value of 1000, you have 1000 simultaneous function calls, which exhausts the memory area reserved for function calls.

This is a problem with recursion in any programming language. The solution is to use a loop instead, which is easy in this case.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,298

Post » Tue May 14, 2013 1:38 pm

thank you ashley
B
19
S
6
G
2
Posts: 188
Reputation: 2,744

Post » Wed May 15, 2013 2:06 am

Deep recursion can commonly cause a stack overrun and it should be avoided in favor of loops whenever possible. I did notice something that could possibly be a problem though.

I couldn't reproduce the 50/50 behavior you described with Chrome. With a value of 500, on average it would work for 4 clicks and then on the fifth and above it would continually produce a minimum call stack size exceeded error. Lower values would do the same, generally requiring more clicks. It sounds like each subsequent call to the function is pushing deeper into the stack and that doesn't seem like something that should be happening.

I'm not a javascript programmer, so I don't how much of a problem this really is.

EDIT: There seems to be a specific cut off for me where the problem simply doesn't happen and where it happens unconditionally somewhere around 408 levels deep. I don't think this is an issue until you hit the critical point.DimensionWarped2013-05-15 02:26:14
B
4
Posts: 17
Reputation: 484

Post » Sun May 19, 2013 12:45 pm

Oh thank you DW, I just saw this.

I will definitely use loops instead of deep recursion. This was an exercise for a procedurally generated graphics project. I just wanted to understand recursion.

B
19
S
6
G
2
Posts: 188
Reputation: 2,744


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 5 guests