An error occurs when the canvas is destroyed and created

error sample link

nomal sample link

When you run the error sample, there is a start button. The render is broken when the button is pressed.

However, if you run the normal sample and press the button, the render does not break.

The difference between the two is that one removes and creates the canvas, but
One refers to the created canvas.

What is the cause?

It’s a bit dangerous for us to download unknown zips.

Could you post the code please on the forum, github or post a link to a PlayCanvas project?

What is the error? Are there any error messages in the browser dev console?

sorry. I misunderstood how to share a project.

I have attached a github link in the reply.

It is not the direct cause of the error, but the corresponding waring is coming out.
“WebGL: INVALID_OPERATION: bindTexture: object does not belong to this context”

thank you.

Yeah, that makes sense. The engine has a reference to the canvas that it is rendering to and creates a WebGL context to it.

Recreating the canvas is likely to cause that error. At the moment, the engine does not support changing canvases after the engine has been created.

So how can we design the structure when the canvas needs to change? Do you have any best case examples?

Afraid it’s not possible without destroying the PlayCanvas application and creating a new one with the new canvas.

What is the use case for having to change canvas?

Reuse canvas when using canvas as a popup.

I am creating after app.destroy without page refresh. If you do not reuse the canvas when creating, an error is coming out.

Can you not hide it and re-add to the dom instead?

I’m a bit confused on what your application is doing?

It looks like you are trying to destroy the entire app and recreate it again?

Yes I want to destroy the entire app and recreate it again.

Hiding is also a way, but I don’t think it’s a fundamental solution.

I destroyed the app and started it again. The expected behavior at this time is normal behavior.

Please compare the index file code in the example. The part where the error occurs is the part I want to do.

I’m a little backed up on work here so won’t be able to look at until next week I think. I’ve created an internal ticket for this.

1 Like

Thanks for making the ticket internally. Can you raise the ticket priority? Path is required for this production.

There is a way we have solved it ourselves, please check whether the action is the right way.

I sent a pull request to github. thank you.

Unfortunately not, it’s currently me that triaging and going through the issues as fast as I can.
Now that you’ve narrowed down the issue, I think someone on the engine team will take a look too

We think this specific issue doesn’t occur on engine 1.50.X. Would you be able to downgrade to the previous for the short term until the team fixes this properly?

1 Like

Okay. Please let me know when it’s resolved, thanks!

PR is in:

1 Like