From 70fc232dbc32f7476a0bf3460b2c40483c455916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 6 Sep 2022 15:43:57 +0200 Subject: [PATCH] GL: unconditionally trim shader compilation/linking messages. Until now it relied on the driver adding a \n after each message. Which happened in 99% cases, but sometimes not, and it is really annoying in that case. Right now I witnessed Mesa giving me a non-newlined message if I call checkLink() and a shader compilation failed before, resulting in nasty output like error: linking with uncompiled/unspecialized shaderAssertion checkLink() failed at /home/mosra/Code/magnum/src/Magnum/Shaders/FlatGL.cpp:248 And I bet I encountered other weird cases, like there being two newlines, or the message being just a newline without any other content, thus spamming the output on every compilation. It's not practical to try to find driver-specific workarounds here, so I'm just trimming always and then rely on Debug adding its own newline after. --- src/Magnum/GL/AbstractShaderProgram.cpp | 22 +++++++++++++++------- src/Magnum/GL/Shader.cpp | 23 ++++++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/Magnum/GL/AbstractShaderProgram.cpp b/src/Magnum/GL/AbstractShaderProgram.cpp index 59768aac7..4b5e53be7 100644 --- a/src/Magnum/GL/AbstractShaderProgram.cpp +++ b/src/Magnum/GL/AbstractShaderProgram.cpp @@ -31,6 +31,7 @@ #ifndef MAGNUM_TARGET_WEBGL #include #endif +#include /** @todo remove once -free */ #include #include @@ -606,17 +607,24 @@ bool AbstractShaderProgram::checkLink() { be said, handle that as well. */ Context::current().state().shaderProgram.cleanLogImplementation(message); + /* Usually the driver messages contain a newline at the end. But sometimes + not, such as in case of a program link error due to shaders not being + compiled yet on Mesa; sometimes there's two newlines, sometimes just a + newline and nothing else etc. Because trying do this in driver-specific + workarounds would involve an impossible task of checking all possible + error messages on every possible driver, just trim all whitespace around + the message always and let Debug add its own newline. */ + const Containers::StringView messageTrimmed = Containers::StringView{message}.trimmed(); + /* Show error log */ if(!success) { - Error out{Debug::Flag::NoNewlineAtTheEnd}; - out << "GL::AbstractShaderProgram::link(): linking failed with the following message:" - << Debug::newline << message; + Error{} << "GL::AbstractShaderProgram::link(): linking failed with the following message:" + << Debug::newline << messageTrimmed; /* Or just warnings, if any */ - } else if(!message.empty()) { - Warning out{Debug::Flag::NoNewlineAtTheEnd}; - out << "GL::AbstractShaderProgram::link(): linking succeeded with the following message:" - << Debug::newline << message; + } else if(messageTrimmed) { + Warning{} << "GL::AbstractShaderProgram::link(): linking succeeded with the following message:" + << Debug::newline << messageTrimmed; } return success; diff --git a/src/Magnum/GL/Shader.cpp b/src/Magnum/GL/Shader.cpp index fdd3036dc..9966b75cf 100644 --- a/src/Magnum/GL/Shader.cpp +++ b/src/Magnum/GL/Shader.cpp @@ -783,17 +783,26 @@ bool Shader::checkCompile() { be said, handle that as well. */ Context::current().state().shader.cleanLogImplementation(message); + /* Usually the driver messages contain a newline at the end. But sometimes + not, such as in case of a program link error due to shaders not being + compiled yet on Mesa; sometimes there's two newlines, sometimes just a + newline and nothing else etc. Because trying do this in driver-specific + workarounds would involve an impossible task of checking all possible + error messages on every possible driver, just trim all whitespace around + the message always and let Debug add its own newline. */ + const Containers::StringView messageTrimmed = Containers::StringView{message}.trimmed(); + /* Show error log */ if(!success) { - Error out{Debug::Flag::NoNewlineAtTheEnd}; - out << "GL::Shader::compile(): compilation of" << shaderName(_type) << "shader" - << "failed with the following message:" << Debug::newline << message; + Error{} << "GL::Shader::compile(): compilation of" << shaderName(_type) + << "shader failed with the following message:" << Debug::newline + << messageTrimmed; /* Or just warnings, if any */ - } else if(!message.empty()) { - Warning out{Debug::Flag::NoNewlineAtTheEnd}; - out << "GL::Shader::compile(): compilation of" << shaderName(_type) << "shader" - << "succeeded with the following message:" << Debug::newline << message; + } else if(messageTrimmed) { + Warning{} << "GL::Shader::compile(): compilation of" << shaderName(_type) + << "shader succeeded with the following message:" << Debug::newline + << messageTrimmed; } return success;