Skip to content

Commit

Permalink
Fixed edge case in OpenGLShader::PreProcess Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Puddlestomper authored and LovelySanta committed Oct 5, 2019
1 parent 033af46 commit 4e0a190
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Hazel/src/Platform/OpenGL/OpenGLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4e0a190

Please sign in to comment.