From 4e0a190a31bd7672dbf8afcdc6c82a6a1fa0c816 Mon Sep 17 00:00:00 2001 From: Adri Wessels Date: Sat, 5 Oct 2019 19:40:10 +0200 Subject: [PATCH] Fixed edge case in OpenGLShader::PreProcess Logic --- Hazel/src/Platform/OpenGL/OpenGLShader.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Hazel/src/Platform/OpenGL/OpenGLShader.cpp b/Hazel/src/Platform/OpenGL/OpenGLShader.cpp index 700bc4510..557832c35 100644 --- a/Hazel/src/Platform/OpenGL/OpenGLShader.cpp +++ b/Hazel/src/Platform/OpenGL/OpenGLShader.cpp @@ -73,18 +73,20 @@ namespace Hazel { const char* typeToken = "#type"; size_t typeTokenLength = strlen(typeToken); - size_t pos = source.find(typeToken, 0); + size_t pos = source.find(typeToken, 0); //Start of shader type declaration line while (pos != std::string::npos) { - size_t eol = source.find_first_of("\r\n", pos); + size_t eol = source.find_first_of("\r\n", pos); //End of shader type declaration line HZ_CORE_ASSERT(eol != std::string::npos, "Syntax error"); - size_t begin = pos + typeTokenLength + 1; + size_t begin = pos + typeTokenLength + 1; //Start of shader type name (after "#type " keyword) std::string type = source.substr(begin, eol - begin); HZ_CORE_ASSERT(ShaderTypeFromString(type), "Invalid shader type specified"); - size_t nextLinePos = source.find_first_not_of("\r\n", eol); - pos = source.find(typeToken, nextLinePos); - shaderSources[ShaderTypeFromString(type)] = source.substr(nextLinePos, pos - (nextLinePos == std::string::npos ? source.size() - 1 : nextLinePos)); + size_t nextLinePos = source.find_first_not_of("\r\n", eol); //Start of shader code after shader type declaration line + HZ_CORE_ASSERT(nextLinePos != std::string::npos, "Syntax error"); + pos = source.find(typeToken, nextLinePos); //Start of next shader type declaration line + + shaderSources[ShaderTypeFromString(type)] = (pos == std::string::npos) ? source.substr(nextLinePos) : source.substr(nextLinePos, pos - nextLinePos); } return shaderSources;