cables-gl / cables_docs

cables documentation docs.cables.gl
https://cables.gl/docs/docs
45 stars 16 forks source link

Shader error log line numbers are incorrect in CustomShader OPs #888

Open LeStahL opened 1 month ago

LeStahL commented 1 month ago

Reproduce using the op below, which has an error in line 5:

{"ops":[{"opId":"a165fc89-a35b-4d39-8930-7345b098bd9d","id":"be5d855d-cd9d-4760-8b8a-012a9de90ebf","uiAttribs":{"translate":{"x":-108,"y":0},"notWorkingMsg":null,"comment":"Click this op and press the edit button to see the editor.\nuResX and uResY are the width and height \nof the mainloop op","subPatch":0},"portsIn":[{"name":"Fragment Code","value":"uniform float uResX;\nuniform float uResY;\n\nuniform float uTime;\nA\nIN vec2 texCoord;\n\n{{MODULES_HEAD}}\nvoid main()\n{\n    vec2 uv = gl_FragCoord.xy/vec2(uResX,uResY);\n    \n    float animGreen = 0.5 + (0.5 * sin(uTime));\n    \n    vec4 col=vec4(uv,animGreen,1.0);\n    \n    {{MODULE_COLOR}}\n    outColor = col;\n}"},{"name":"Vertex Code","value":"\n{{MODULES_HEAD}}\nIN vec3 vPosition;\nIN vec2 attrTexCoord;\nIN vec3 attrVertNormal;\nIN float attrVertIndex;\nOUT vec2 texCoord;\nOUT vec3 norm;\nUNI mat4 projMatrix;\nUNI mat4 viewMatrix;\nUNI mat4 modelMatrix;\nvoid main()\n{\n   texCoord=attrTexCoord;\n   norm=attrVertNormal;\n   vec4 pos=vec4(vPosition,  1.0);\n   mat4 mMatrix=modelMatrix;\n   {{MODULE_VERTEX_POSITION}}\n   gl_Position = projMatrix * (viewMatrix*mMatrix) * pos;\n}"},{"name":"Use As Material","value":1},{"name":"uResX","value":0},{"name":"uResY","value":0},{"name":"uTime","value":0}],"portsOut":[{"name":"Has Errors","value":true}]}]}

The error is displayed as

[cgl_shader] 
customshader shader linking fail...
[cgl_shader] 
ERROR: 0:28: 'A' : syntax error
[cgl_shader] 
bad line: 28: A 

I use the version at https://cables.gl/ to reproduce.

LeStahL commented 3 weeks ago

There is an easy workaround that fixes this:

You can add #line 2 to the very first line of your shader source.

pandrr commented 3 weeks ago

oh interesting, i did not know about this...

i am thinking about having a internal system that adds comments to each line. so you can later know which line was which in different shadermodules, that get combined into one big shader.