From 7fdad7c010c7e9e40a377fbedb4b39797517e09e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 19 Aug 2017 17:20:03 -0300 Subject: [PATCH] Workaround for off-by-one line numbers in shader validation errors. --HG-- branch : minor --- src/modules/graphics/wrap_Graphics.lua | 29 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/wrap_Graphics.lua b/src/modules/graphics/wrap_Graphics.lua index 386d2e02e..4d1157fe2 100644 --- a/src/modules/graphics/wrap_Graphics.lua +++ b/src/modules/graphics/wrap_Graphics.lua @@ -320,7 +320,7 @@ local function createShaderStageCode(stage, code, lang, gles, glsl1on3, gammacor GLSL.FUNCTIONS, GLSL[stage].FUNCTIONS, custom and GLSL[stage].MAIN_CUSTOM or GLSL[stage].MAIN, - (lang == "glsl3" or gles) and "#line 1" or "#line 0", + ((lang == "glsl1" or glsl1on3) and not gles) and "#line 0" or "#line 1", code, } return table_concat(lines, "\n") @@ -403,9 +403,19 @@ function love.graphics._shaderCodeToGLSL(gles, arg1, arg2) end function love.graphics._transformGLSLErrorMessages(message) + local compiling = true local shadertype = message:match("Cannot compile (%a+) shader code") + if not shadertype then + compiling = false + shadertype = message:match("Error validating (%a+) shader") + end if not shadertype then return message end - local lines = {"Cannot compile "..shadertype.." shader code:"} + local lines = {} + if compiling then + lines[#lines+1] = "Cannot compile "..shadertype.." shader code:" + else + lines[#lines+1] = "Error validating "..shadertype.." shader code:" + end for l in message:gmatch("[^\n]+") do -- nvidia compiler message: -- 0() : error/warning [NUMBER]: @@ -414,14 +424,19 @@ function love.graphics._transformGLSLErrorMessages(message) -- ati compiler message: -- ERROR 0:: error/warning(#[NUMBER]) [ERRORNAME]: linenumber, what, message = l:match("^%w+: 0:(%d+):%s*(%w+)%([^%)]+%)%s*(.+)$") - if not linenumber then - -- OSX compiler message (?): - -- ERROR: 0:: - what, linenumber, message = l:match("^(%w+): %d+:(%d+): (.+)$") - end + end + if not linenumber then + -- OSX compiler message (?): + -- ERROR: 0:: + what, linenumber, message = l:match("^(%w+): %d+:(%d+): (.+)$") + end + if not linenumber and l:match("^ERROR:") then + what = l end if linenumber and what and message then lines[#lines+1] = ("Line %d: %s: %s"):format(linenumber, what, message) + elseif what then + lines[#lines+1] = what end end -- did not match any known error messages