How to get onError when Shader fails to compile for a PostProcess

How can I get an onError callback when a shader fails to compile and is assigned to a PostProcess?

When assigning shaders to a PostProcess, I cannot get the onError callback to fire.
Below is some example code of what I mean.
I can only get the global error callback to fire off, but it lacks context as to which shader is failing.

BABYLON.Effect.ShadersStore[`${fragmentID}FragmentShader`] = shaderPass.fragmentGLSL

const postProcess = new BABYLON.PostProcess(`Shader`,
    fragmentID,
    [
        ...STANDARDUNIFORMS,
    ],
    SAMPLER,
    ratio,
    camera);

// DOESNT WORK!!!!
postProcess.getEffect().onErrorObservable.add((error) => {
    console.error(error)
})

// DOESNT WORK!!!!
postProcess.getEffect().onError = (effect, errors) => {
    console.error("Shader Error", errors)
}

// Works but lacks shader context
BABYLON.Logger.Error = (message) => {
    console.error(message)
}

Additionally, this code looks like it could fire off on the onError callback, however previousPipelineContext is always nil for a newly created Effect.

 if (previousPipelineContext) {
            this._pipelineContext = previousPipelineContext;
            this._isReady = true;
            if (this.onError) {
                this.onError(this, this._compilationError);
            }
            this.onErrorObservable.notifyObservers(this);
        }
1 Like

Yeah, I agree. I don’t see a reason to check if this context exists to log the error. @sebavan - any issue you see here with removing this “if” ?

as well as removing the this._isReady = true
Just Report!
(I don’t know why the ready state is changed)

Yup smthg is weird here and probably related to the fallbacks not being used in Post Pro.

I ll try to have a fix later tonight.

Will be fixed by Fix effects onError notifications by sebavan · Pull Request #13007 · BabylonJS/Babylon.js · GitHub

2 Likes