Multicanvas shader compile error because of comment line

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Multicanvas shader compile error because of comment line

Post 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
ecoste
Prole
Posts: 6
Joined: Tue Jul 06, 2021 7:06 pm

Re: Multicanvas shader compile error because of comment line

Post 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.
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Re: Multicanvas shader compile error because of comment line

Post 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.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Multicanvas shader compile error because of comment line

Post 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)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests