Page 1 of 1

Multicanvas shader compile error because of comment line

Posted: Mon Jun 01, 2020 4:58 am
by Sasha264
Good day!

Here is 2 formats for pixel shader: 1) with arguments and with return value and 2) without arguments and with love_Canvases 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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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
I already posted bug issue to github, but maybe here someone will tell me that I am doing something wrong :3

Re: Multicanvas shader compile error because of comment line

Posted: Sat Aug 07, 2021 11:30 pm
by ecoste
+1 ran into this as well on my own. When I delete a bunch of comments it suddenly works, very weird.

edit: I'm pretty sure it's because there's a bug in this match line over here as it matches the effect string even if it's in a comment https://github.com/love2d/love/blob/e9c ... r.lua#L342

solution: pre-process the shader code and remove all the commends before running that.

Re: Multicanvas shader compile error because of comment line

Posted: Sun Aug 08, 2021 11:39 am
by AuahDark
The current shader entrypoint detection is simple Lua's

Code: Select all

string.match
/

Code: Select all

string.find
which doesn't take comments into account. The current solution is to remove the commented entrypoint.

Re: Multicanvas shader compile error because of comment line

Posted: Sun Aug 08, 2021 1:14 pm
by ReFreezed
You could also add an error to the code in the comment so LÖVE doesn't match it.

Code: Select all

//v%ec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord)