Create screenshot generate blank/black image

Hello guys,

I use CreateScreenshotUsingRenderTarget method to create screenshot of canvas at our site and it’s working for 99% of the time. Unfortunately lately some of our users started to report issue with this generating black image instead of product.

I have done some investigation and was able to track down that issue was probably related to too high number of samples (8). And lowering it to 1 seems to fix the problem. However that change results in visible drop in quality of generated images. So I’m rather reluctant to use that solution.

For now we only get report of problem happening only on Chrome. Initially I thought it could be related to hardware since I was only able to reproduce it on old Macbook from 2011. But then I got reports that it also happens for users with newer computers. Most of them seems to use Windows 7.

Out code for generating screenshot looks like

function captureScene(scene, callback) {
	const mimeType = 'image/jpeg';

    scene.clearColor = new Color3(255, 255, 255);

    Tools.CreateScreenshotUsingRenderTarget(scene.getEngine(), scene.activeCamera, {width: 1920, height: 1080}, callback, mimeType, 8, false);

We are using Babylon.js 4.0.3

Do you have any idea what may be the root of this issue? Is there other possible fix to that other then lowering samples number. Eventually maybe there is some way to get number of supported samples…


Unfortunately it looks like a browser issue to me :frowning: Would you be able to get more logs from the users console ?

One possible problem would be that some mesh effect/texture are not ready yet when taking the screenshot and so are not rendered.

You can try to call the screenshot function only if everything is ready in the scene:

function captureScene(scene, callback) {
    scene.executeWhenReady(() => {
        const mimeType = 'image/jpeg';
        scene.clearColor = new Color3(255, 255, 255);
        Tools.CreateScreenshotUsingRenderTarget(scene.getEngine(), scene.activeCamera,
            {width: 1920, height: 1080}, callback, mimeType, 8, false);
1 Like

Hi, @Evgeni_Popov @sebavan thanks for the comments, probably worthwhile us adding it, however, I think it’s not this because this is an image generation which is run manually by clicking an icon and then a pop up where you pick the image size and type. I cannot imagine the user trying to run this before they edit the configuration @Marcin_Zamelskiwill be best to reply however

Example Product can be found here
you can click generate an image in the top icons

I can’t either, but I’m still able to get a blank (white) screenshot by refreshing the page then quickly cliking on the “save” icon and “Generate image” button before the asset is downloaded/displayed.

Just to be extra sure, you could enable the “save” icon (as well as the “export” and “generate pdf” too) only when the scene is ready.


Thanks for answers.
I was mostly trying to export after everything was loaded. And error still pop out. We will of course block it until everything is loaded.

@sebavan Ok it looks like I did rookie error and didn’t checked warnings (I use mostly errors) in console. It looks like console clearly says that there is too big number of samples. Question is how do I know what is the range for it then.

1 Like

you can access it with engine.getCaps().maxSamples :slight_smile:


Ha ha well your absolutely right good point.
We will block the UI, it’s actually on my list for the team to do as of right now :slight_smile:

I see Marcin has chimed in so I am going to leave it him.

Thanks for swift replies all :slight_smile:

1 Like

Unfortunately it looks like that variable was introduced in newer version of Babylon since it’s missing at 4.0.3. But since I know what I was looking for I checked source code and was able to get that number by myself.

Anyway it returns 4 samples on my mac what is clearly too big since it results in black image.

However I can use it to at least distinguish between if it support our initial 8 or not and make it 8/1. It’s still much better then dropping to 1 for everyone.

Big thanks for help!

1 Like

On mac it returns 4 but fails ??? could you share on which browser as it might be good to let them know ?

@sebavan Marcin was working on some important task so probably missed this reply. I saw it now only my self.
I checked our internal project chat and found this (see the screenshot).

So it’s a MacBook with chrome that we tested with. It’s from 2011 since all other machines it worked fine on. Also you can see safari on Mac was fine.

Marcin told me that with chrome only 1 samples works but it returns that 4 should work.

So 2011 MacBook with chrome.

Here is the screenshot from the internal chat we were having in the subject.

So might be worth creating an issue on the chrome side ?

you mean reporting to chrome as a bug?

Yup cause they provide an unsupported max number of samples it looks like.

1 Like