From d3ea83992c7a2456066c92d811a21a715db797c9 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 13 Nov 2025 09:39:53 +0800 Subject: [PATCH] [Fix]: (MG_Util/ShaderTranspiler/ShaderSourceProcessor): fix trailing `\n` not get removed --- .../ShaderTranspiler/ShaderSourceProcessor.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp b/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp index 5a83a113..682ad838 100644 --- a/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp +++ b/MobileGL/MG_Util/ShaderTranspiler/ShaderSourceProcessor.cpp @@ -4,14 +4,6 @@ namespace MobileGL { namespace MG_Util { namespace ShaderTranspiler { void PreprocessShaderSource(ShaderStage stage, String& source) { - // remove #line directives - SizeT linedirPos = source.find("#line"); - while (linedirPos != std::string::npos) { - SizeT newlinePos = source.find('\n', linedirPos); - source = source.replace(linedirPos, newlinePos - linedirPos, ""); - linedirPos = source.find("#line", linedirPos); - } - // remove multi-line comment size_t commentStartPos = source.find("/*"); while (commentStartPos != std::string::npos) { @@ -21,6 +13,15 @@ namespace MobileGL { commentStartPos = source.find("/*", commentStartPos); } + // remove #line directives + SizeT linedirPos = source.find("#line"); + while (linedirPos != std::string::npos) { + SizeT newlinePos = source.find('\n', linedirPos); + // + length of "\n" + source = source.replace(linedirPos, newlinePos - linedirPos + 1, ""); + linedirPos = source.find("#line", linedirPos); + } + // force #version ShaderProfile profile = ShaderProfile::Core; SizeT versionPos = source.find("#version");