frontend icon indicating copy to clipboard operation
frontend copied to clipboard

Function resulting in deep call stack fails multiple times before succeeding

Open zhongfu opened this issue 5 years ago • 1 comments

Attempting to run the following snippet multiple times will result in Maximum call stack size exceeded (at least on Chrome 84), but repeated attempts will eventually result in successful execution (usually 5 times, but sometimes a bit more).

Note that this program will likely cause your JS engine to run out of memory too.. but that might be a separate issue entirely. You'll know that it's running once the tab hangs.

function hook(frac) {
    return beside_frac(
        1 - frac,
        stack(square, blank),
        square);
}

function spiral(thickness, depth) {
    return depth === 0
        ? blank
        : stack_frac(
            thickness,
            hook(thickness * 0.5),
            quarter_turn_right(spiral(thickness, depth - 1)));
}

function fractal(pic, n) {
    return n === 1
        ? pic
        : beside(
            pic,
            fractal(stackn(2, pic), n - 1));
}
show(fractal(spiral(1/5, 1000), 15));

Interestingly enough, each failed attempt to run that snippet will result in the aforementioned error occurring at a different line number -- usually one of -1, 2, 3, 4, or 14.

zhongfu avatar Aug 21 '20 19:08 zhongfu

Seems to be an issue in webGLrune.js. I'm guessing it's some sort of infinite loop arising from floating point error/insufficient precision causing something to become 0 or NaN.

angelsl avatar Aug 21 '20 19:08 angelsl