Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Gracefully exit on a shader compile error — Gideros Forum

Gracefully exit on a shader compile error

SinisterSoftSinisterSoft Maintainer
edited August 2016 in Code snippets
If you use a shader then on some systems that shader may not compile correctly (at run-time), this will result in an error that doesn't normally return properly to your program. Here is a way of doing it 'gracefully'...
    local result,reply=pcall(Shader.new,"vShader","fShader",0,{
        {name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true}, 
        {name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false}, 
        {name="fTexture",type=Shader.CTEXTURE,vertex=false},  }, 
        {{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0}, 
        {name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0}, 
        {name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0}, })
        
    if result then
        shader=reply
    else
        print("shader error:",reply)
    end
Just replace the Shader.new paramaters with your parameters.

Because 'shader' will be nil if it fails then no harm done if you set a sprite to use that nil shader, as nil will just set the shader to the Gideros default.

Hope you all find this useful. :)

Likes: antix

Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
+1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.