diff --git a/Hazel/src/Platform/OpenGL/OpenGLShader.cpp b/Hazel/src/Platform/OpenGL/OpenGLShader.cpp index 57598bc31..c7191f6b8 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;