Autoclear = true not working after re-registering canvas

In my application the canvas element can be removed and re-added to the dom.

This has worked fine until I enabled a transparent clear color. With a transparent clear color I get the effect that is demonstrated by this playground: Babylon.js Playground.

I tried setting myScene.autoClear = true but it does not seem to have an effect.

I suspect something happens when I’ve registered the new canvas element:

updateCanvas(canvas) {
	const engine = this._scene.getEngine();
	const camera = this.get('camera');

	engine.inputElement = canvas;

	engine.registerView(canvas, camera);

I guess I need to change some property somewhere after I’ve re-registered the new canvas element but I’m not sure what.

try setting clearBeforeCopy to true when registering a view
engine.registerView(canvas, camera, true);


That did the trick! Thank you!

I tried to re-create the issue in an updated playground but for some reason I could not reproduce it. I wonder if it’s due to a later Babylonjs version used in the playground?


you’re welcome, I struggled with this same issue a few months ago :stuck_out_tongue:

in your playground, if you set the scene clearColor to a transparent color you’ll reproduce the same behaviour you described.

1 Like

Gotcha (doh!). Thanks again!