Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

'Possible infinite loop' - how can I tell which script causes this?

On occasion the API sandbox for my game shuts down on account of a 'potential infinite loop' but the error message is not as revealing as I would like as to help me figure out: A) what script is causing the issue B) where in the script the loop is Is there an easy way for me to get this information, like a stack trace or other debugging tool? Without knowing which of the scripts I've imported/written is causing the error it's hard to fix, and I don;t want to have to delete scripts until it doesn't happen because it's only an intermittant problem so I have no easy way of determining whether deleting a script actually worked or not.
1600551197
The Aaron
Roll20 Production Team
API Scripter
There isn't an easy way to track this down. However, I can give you some insight into what is happening that might help you to find it.  The API operates in a sort of cooperative multitasking system. There are lots of scripts running, and they each yield their execution every so often to allow other scripts to run. This happens when an event in a script finishes being processed, or when a script defers what it is doing using setTimout() or similar.  When scripts aren't yielding often enough (within 60 or 120 seconds, don't recall which) there is a separate process (a watchdog timer) that kills the sandbox because it assumes there is an infinite loop or it's otherwise locked up. "Possible infinite loop detected." What this almost always turns out to be is a script trying to do too much when an event occurs. For example, finding every attribute in the game that contains some thing that looks like a die roll. What you want to look for is a script that's doing a findObjs() call with very little restriction and then processing all of the results in some expensive way. The way to fix it is to construct a list of results and a function that processes the next result and then calls itself with setTimeout(func,0). That 0 delay defers the execution until after a yield to the sandbox which prevents the possible infinite loop from the watchdog timer. I can get you an example of coding that if it will help. 
Example coding would be fantastic, I think most of my findObjs calls are relatively restricted (usually only finding a specific token) but that's a good place to start for sure!
1600947577
The Aaron
Roll20 Production Team
API Scripter
Sorry for the delay, I completely forgot to get back to you on this! Here's a thread where I just provided two examples:&nbsp;&nbsp;<a href="https://app.roll20.net/forum/post/9214890/createobj-attribute-taking-too-long-and-getting-possible-infinite-loop-detected-shutting-down-error-any-way-to-speed-it-up-or-avoid-the-error/?pageforid=9215045#post-9215045" rel="nofollow">https://app.roll20.net/forum/post/9214890/createobj-attribute-taking-too-long-and-getting-possible-infinite-loop-detected-shutting-down-error-any-way-to-speed-it-up-or-avoid-the-error/?pageforid=9215045#post-9215045</a>
Well in other news I may have found the offending script. Disabled one that looked like it might be a bit greedy with its findObjs calls and haven't had the error re-occur. I just need to figure out if and how I can change it to make it safer! XD
1600957994
The Aaron
Roll20 Production Team
API Scripter
Feel free to post it, or PM it to me and I'll be happy to look at it.
It's a long one that I grabbed off a YouTube tutorial, so I'll PM it :D