How to get shader gl compilation errors from Babylon?

I’m working on a shader editor with support for Babylon. I’m using processFinalCode to put my own raw GLSL into a Babylon shader. When I get compilation errors, the only place I can see them is in the console. I’d like to surface these in the UI.

I see that program link errors are attached to an internal pipelineContext variable. Is this variable exposed to end users? It also looks like, from the source code, that shaders are deleted if they’re failed to link, they’re deleted? I’m not sure - however when I call mesh.material.getEffect() after a failed compile - it’s undefined.

I could get there with - but I’m not sure if it’s possible to get a material’s gl program?

Hijacking Logger.Error may be an option, although lines like these:

            if (lineErrorVertex) {
            if (lineErrorFragment) {

mean that I can’t as easily intercept needed messages, as these have no prefix string

1 Like

Hey @andyray, can you hook your code into the effect.OnError callback?

Else the pipelineContext is available on effect.getPipelineContext property :slight_smile:


Hi @Deltakosh , when I do this:

    const shaderMaterial = new BABYLON.PBRMaterial(`pbr${id()}`, scene);
    const effect = shaderMaterial.getEffect();
    effect.onError = ...;

Typescript says everything is fine, but effect is undefined at runtime.

You should hook into onEffectCreatedObservable as the effect is stored per submesh for caching purpose

Hey @sebavan .
I stumbled across this topic and tried what you suggested in the last post (hooking into onEffectCreatedObservable) thought the effect is still undefined for me.
Could it be that there is some flaw in the architecture here?

Hmm it looks like getEffect() still returns undefined but you can use the effect in the callback parameter like below instead. :slight_smile: