Camera w/ Multiple Post Processing Effects Crashes on Re-Enabling

I have a project w/ 3 cameras
The 1st camera is for the main menu, has scenes and post processing on it (bloom, fxaa, vignette, and LUT found here: PlayCanvas 3D HTML5 Game Engine ). Once the play button is pressed, it is disabled and the gameplay camera is enabled.

The gameplay camera has post processing (fxaa, blend, vignette, and the LUT). The game plays and then gets to the end screen. The gameplay camera is turned off and the end scene camera is turned on.

The end scene camera has the same post processing as the main menu camera.

Once play again is pressed, the end scene camera is turned off and the gameplay camera is turned back on. Turning the camera back on causes a crash:

[playcanvas.min.js?version=1.51.5:6]: Uncaught TypeError: Cannot read properties of undefined (reading 'width')

TypeError: Cannot read properties of undefined (reading 'width')
    at t.get (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:368967)
    at e.i.initRenderTarget (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:338578)
    at e.i.updateBegin (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:340361)
    at Object.Fs [as drawFullscreenQuad] (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:374772)
    at VignetteEffect.render (https://launch.playcanvas.com/api/assets/files/PostEffects/posteffect-vignette.js?id=65664227&branchId=65004c90-f4bd-4f4b-8dc2-a5aacc82f1c5:69:12)
    at enabled.effects.length.camera.onPostprocessing (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:841546)
    at t.e.renderComposition (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:473654)
    at i.n.render (https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:1178794)
    at https://launch.playcanvas.com/editor/scene/js/engine/playcanvas.min.js?version=1.51.5:6:1188783

At first I noticed that it was the vignette post effect, so I disabled it all together and the crash still happens but with a different effect. So I disabled all effects and turned one on, disabled the camera, enabled the camera and it worked fine (did this for each effect). So then I thought it was a combination of specific effects, it turns out that it doesn’t matter which 2 effects are on but if it is more than one post processing effect it always crashes.

The gameplay camera starts the game turned off. It is only when it is re-enabled does it crash.

All cameras are priority 1

Hi @derek9nine,

I think that happened in a project of mine a few months ago, but I wasn’t sure if it was my implementation or an engine bug.

What I did back then after switching cameras, to avoid this exact error, was a hack like this:

// re-create post effects queue
    cameraEntity.camera.postEffects.destroy();
    try {
        cameraEntity.camera.postEffects = new pc.PostEffectQueue(this.app, cameraEntity);
    } catch (e) { }

// toggle on/off each effect to trigger the action that adds them to the effects queue
        cameraEntity.script.ssao.enabled = false;
        cameraEntity.script.ssao.enabled = true;

        cameraEntity.script.bloom.enabled = false;
        cameraEntity.script.bloom.enabled = true;

// etc
2 Likes

I’m not sure where the crash is coming from, likely a bug in the engine. But I’d say that using a single camera with post-effects might be a good idea, as otherwise all cameras would have post-effect frame-buffers allocated. It’s possible they got deleted when camera is disabled, but I’m not entirely sure.

3 Likes

Ideally a single camera would be great if I could get away with it and have a very particular and nit picky client be happy :smiley:

1 Like

@Leonidas This did the trick. Thank you so much. Luckily I only have to do it once, maybe twice in a standard use case.

Appreciate the help

2 Likes