Taking a screenshot sometimes hangs

CreateScreenshotUsingRenderTarget sometimes gets stuck in an endless loop waiting for texture to become ready:

    const texture = new RenderTargetTexture("screenShot", targetTextureSize, scene, false, false, 0, false, Texture.BILINEAR_SAMPLINGMODE, undefined, enableStencilBuffer, undefined, undefined, undefined, samples);
    ...
    const renderWhenReady = () => {
        console.debug('renderWhenReady', texture.isReadyForRendering(), camera.isReady(true))
        if (texture.isReadyForRendering() && camera.isReady(true)) {
            ...
        }
        else {
            setTimeout(renderWhenReady, 16);
        }
    }

This prints renderWhenReady false true endlessly. But it’s intermittent - I haven’t been able to replicate in a PG.

When you get stuck in an endless loop, you should break inside the debugger to see the call stack. This should help you understand where the problem is coming from. If you can install a repro somewhere (even if not in the playground), that might also help you/us debug it.

1 Like