Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Recursion problem

Author
Message
Rais
21
Years of Service
User Offline
Joined: 7th Jul 2003
Location:
Posted: 1st Apr 2016 23:05 Edited at: 1st Apr 2016 23:19
I'm using a recursive backtracker to create random mazes. The function works perfectly with small mazes of 10 x 10, but with anything bigger than 15 x 15 the program crashes. I've narrowed down the problem to be recursion. When the main function has called itself about a 100 times it crashes.

Does AppGameKit have some kind of limitation on this?

Cheers.

Edit. Forgot to say, using AppGameKit 2.0.18 tier 1.
JohnStabler
AGK Bronze Backer
11
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 1st Apr 2016 23:22 Edited at: 1st Apr 2016 23:23
For one of my recent games, Runes of Anarchy, I used a recursive algorithm to create a maze. Unfortunately I hit upon this problem as well. There does seem to be some undocumented limit.

I got around it by using an array to create and manage my own stack and pointer. I suggest you do the same until there is a fix.
Hi. I am a real person (not a bot). I appreciate all replies and advice.
Rais
21
Years of Service
User Offline
Joined: 7th Jul 2003
Location:
Posted: 2nd Apr 2016 09:25
That's a bugger but good to know its not just me. Time to rewrite some of the code...

Cheers
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Apr 2016 10:31
It would be useful to log() the number of recursions, and check if it is some magic number like 256.
You 15x15 maze will keep you under 256 (225), but 16x16 will take you over.

This would make sense and is trackable, so maybe a limit that can be fixed by Paul.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Apr 2016 12:06
maybe u can use, its an alternative.
copy/paste from web.
Quote: "If your code uses tail recursion (that is, the function returns the result of every recursive call directly without any other processing) then it's possible to rewrite the function imperatively without a stack:

function dosomething(a,b,c,d)
{
// manipulate a,b,c,d
if (condition)
return dosomething(a,b,c,d)
else
return something;
}

Into:

function dosomething(a,b,c,d)
{
while (true)
{
// manipulate a,b,c,d
if (condition) continue;
else return something;
}
}
"
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Rais
21
Years of Service
User Offline
Joined: 7th Jul 2003
Location:
Posted: 2nd Apr 2016 14:44
Hiya,
There doesn't appear to be a magic number as such, but I think there is a memory limit somewhere. On my maze generation function the program crashes at 102 recursions, but if you do something as silly as:


it crashes at 478. It must be running out of memory somewhere.

I have the program working now just by using a few arrays and keeping track of everything manually.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Apr 2016 21:27
You could always try emailing your code to Paul. His email address can be found at the bottom of his posts.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 6th Apr 2016 16:39
Sounds like a stack overflow, I'll increase the stack size from 1024 to 32768 for the next version
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Apr 2016 17:31 Edited at: 6th Apr 2016 17:33
@Paul
is it possible to make a Command for it for Compiler or at Runtime?
GetStackSize,SetStackSize,AddStackSize
at runtime we can add space or give a warning without a crash at limit.
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th Apr 2016 00:36 Edited at: 7th Apr 2016 00:37
I've added an error when run in debug mode so it won't crash anymore, but adding a Tier 1 command that modifies the interpreter itself isn't trivial, so I won't be adding that anytime soon.

Login to post a reply

Server time is: 2024-09-29 13:23:11
Your offset time is: 2024-09-29 13:23:11