Error Script appears to be hung

Started by RickJ, Sun 29/07/2012 03:55:57

Previous topic - Next topic

RickJ

If I call the following function 3 or more times I get the "infinite loop" run time error.  This code has worked previously without any problems.  Seems like the infinite loop counter ought to be reset when the function returns.  Putting in the Wait(1) instruction seems to cause the reset.  Hmmm, also putting in the explicit return also seems to trigger the reset.  In any case there needs to be something about this in the manual with regard to the while statement and the section about scripting loops.

Code: AGS

function InitModel() {
	int mx, tx;

	mx = 0;
	while (mx<2000) {
		// do something
		tx = 0;
		while (tx<50) {
    			// do something
			tx++;
		}
		mx++;
	}		
	Wait(1);     // Otherwise we get a runtime error for too maany loops??
}


Calin Leafshade

Hmm, I'm not so sure that the counter should reset on the function return since the counter is part of the call stack as a whole rather than a single function. The noloopcheck keyword can be used to circumvent issues like this though.

Crimson Wizard

#2
I just checked the engine code. It looks like that the loop counter is reset only when the next main game loop iteration is run.
That means exactly that you must pass execution to the engine once in a while either by returning from event handler (not just your function), or by calling Wait.

One may say consecutive loops are counted as one. Something not elaborated in the manual well enough.

RickJ

Calin, Crimson,

Thanks for the info.   

Notes for manual update:

while
- check for infinite loops
- see also (noloopcheck)

noloopcheck
- check for infinite loops
- 150,000,000 loops per script execution
- reset on script completion or on wait() instruction
- see also (while, function)

SMF spam blocked by CleanTalk