Screenshot functionality, multiple download prompts

Hi guys.

I have an issue with the CreateScreenshotUsingRenderTarget functionality.

So I created an app where you can upload the model and it will be rendered in the scene.

You can see that when loaded I have two buttons, one is to download the png using CreateScreenshotUsingRenderTarget function which works fine.

Other button enables you to upload different file so you can use it in the viewer.

The issue happen when I upload several models one after the other. Everything works fine with the viewer. Models switch and render properly, but when I use downloadPNG button after uploading several files I get multiple prompts for download (one for each model that was uploaded in the viewer)

After every re-upload i dispose engine and the scene. Is there anything else I need to do?

What can I do to get only the latest download prompt, any ideas?

Thanks

Well you have to tell us more:) like how is the code you use to donwload files. This seems related to your code unless I misunderstood something

It’s basic usage of the function provided by Babylon.

image

I invoke downloadScreenshot function like this

image

When I want to upload different file.

First I dispose the existing engine/scene. Then I call createScene function to create new one.

image

I am using assetManager to load a file

image

I would create a playground, but it’s kinda tricky for me to do that.

can you repro on your own page with .max.js so I can check the code?

Can this help you.

src/index.js
and
server.js

is where all things happen

I’m sorry :frowning: but we are pushing the release right now so I can’t install your repo and stuff :frowning: I need a repro I can dig into quickly (something live)

Thant being said I’m pretty confident it would be easier for you to simply drop a breakpoint in the screenshot function and see why it is called multiple times

But the screenshot function is literally Your method for creating screenshots.

CreateScreenshotUsingRenderTarget

That’s it. I call that, and I get downloaded file. I am not sure where can I put breakpoint there.

I don’t have a lot of time myself at the moment. I will keep looking into it and come back if I don’t manage to find a solution. Thank you

For instance are you not registering the click event handler multiple times?

Yes, it is the problem:

        downloadButton.addEventListener("click", ()=>{
            downloadScreenshot(engine, camera);
        })

is executed each time createScene is called (same thing for uploadButton.addEventListener and closeButton.addEventListener).

Yes. That’s indeed the case. I missed that completely. Thank you guys for your help, I appreciate it.