Screenshot RangeError on certain GPUs

Using Tools.CreateScreenshotUsingRenderTarget on certain machines, I found that I was getting a RangeError on TypedArray.set (used inside of Tools.DumpFramebuffer on the line that says: castData.set(data);).

What was happening was that the data generated by
var data = engine.readPixels(0, 0, width, height);
Was a different length than the castData generated by
var imageData = context.createImageData(width, height);
The reason for that seemed to be that context.createImageData at a low level ends up clamping the width and height based on the width and height of the _gl instance, which was always an integer, but the engine.readPixels uses the floating point width and height passed in.

So, for example, if my canvas was 900.5 px by 600.8px, the data array would be slightly larger than the imageData array, and the RangeError would result.

In order for me to fix it, i just had to do a Math.floor on the width/height i pass in to CreateScreenshotUsingRenderTarget, but i thought i would pass these findings along to you guys, and maybe the math.floor should occur inside of the DumpFramebuffer or somewhere within the babylon code to ensure that it works.

Sounds like a good fix…Do you mind doing a PR?

Not at all; just wasn’t sure if there was a better place to do this math.floor; would you recommend doing it right at the beginning of CreateScreenshotUsingRenderTarget, or just inside of DumpFramebuffer, or somewhere in between?

I would say right at the beginning
Thanks :slight_smile: