Multicanvas shader compile error because of comment line
Good day!
Here is 2 formats for pixel shader: 1) with arguments and with return value and 2) without arguments and with love_Canvases[i] assignments. I was developing some shader and switching between those two formats back and forward with commenting some lines. And noticed some strange behavior. Here is simplified situation:
function love.load()
shader = love.graphics.newShader([[
uniform Image MainTex;
//vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord)
void effect()
{
vec4 texturecolor = Texel(MainTex, vec2(VaryingTexCoord));
love_Canvases[0] = texturecolor * VaryingColor;
love_Canvases[1] = texturecolor * VaryingColor;
}
]])
end
Here is commented line contains "argumented" header. If I completely remove this line, shader compiles successfully. But with that line I get error:
Error: Error validating pixel shader code:
Line 1: ERROR: 'MainTex' : redefinition
So, the shader compilation depends on existence of commented line o_O
Also, maybe it's not important, but maybe it can be helpful: If I remove MainTex declaration from above script, I will get another error: That one for love 11.3:
Error: Error validating pixel shader code:
Line 5: ERROR: 'love_Canvases' : undeclared identifier
Line 5: ERROR: 'love_Canvases' : left of '[' is not of type array, matrix, or vector
Line 5: ERROR: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
And that one for love 11.2:
Error: Cannot compile shader:
ERROR: Linking fragment stage: No function definition (body) found:
effect(vf4;s21;vf2;vf2;
ERROR: Linking fragment stage: Cannot use both gl_FragColor and gl_FragData
Shader entry point detection in LOVE is not perfect. It doesn't care whetever the entry point is commented. It will took the first match found.
@MikuAuahDark Hmm, could it implemented so it will check weather the line starts with a "//" and ignore it if it is?
That would be fairly simple. But then you'd probably also expect it to work when the line has the /* */ type of comments. And when the line is inside /* */ comments but those comments don't start/end on the same line. And when #if is used.
Basically we'd have to implement a whole parser just to make it work well, with the current approach.
Code in comments is now avoided when parsing entry point functions, as of e13b007.