Skip to content

Commit

Permalink
[GL3+] Fix leak parsing GLSL shaders (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed May 1, 2024
1 parent 2ca9dc9 commit cb24984
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions RenderSystems/GL3Plus/include/GLSL/OgreGLSLPreprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ namespace Ogre
*/
char *Parse( const char *iSource, size_t iLength, size_t &oLength );

/** Parse the input string as a preamble (i.e. to define a lot of enums).
@param iSource
The source text containing preamble macros.
@param iLength
The length of iSource text in characters.
@return
False on errors. True on success.
*/
bool ParsePreamble( const char *iSource, size_t iLength );

/**
* An error handler function type.
* The default implementation just drops a note to stderr and
Expand Down
6 changes: 6 additions & 0 deletions RenderSystems/GL3Plus/src/GLSL/OgreGLSLPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,4 +1437,10 @@ namespace Ogre
return retval.Buffer;
}

bool CPreprocessor::ParsePreamble( const char *iSource, size_t iLength )
{
Token retval = Parse( Token( Token::TK_TEXT, iSource, iLength ) );
return retval.Type != Token::TK_ERROR;
}

} // namespace Ogre
4 changes: 2 additions & 2 deletions RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ namespace Ogre
replaceVersionMacros();

// Mask out vulkan_layout() macros
size_t unusedVal = 0;
const String preamble =
"#define vulkan_layout(x)\n"
"#define vulkan( x )\n"
Expand All @@ -180,7 +179,7 @@ namespace Ogre
"#define vkSampler2DArray( a, b ) a\n"
"#define vkSampler3D( a, b ) a\n"
"#define vkSamplerCube( a, b ) a\n";
cpp.Parse( preamble.c_str(), preamble.size(), unusedVal );
cpp.ParsePreamble( preamble.c_str(), preamble.size() );

// Pass all user-defined macros to preprocessor
if( !mPreprocessorDefines.empty() )
Expand Down Expand Up @@ -240,6 +239,7 @@ namespace Ogre
const char *src = mSource.c_str();
size_t src_len = mSource.size();
char *out = cpp.Parse( src, src_len, out_size );

if( !out || !out_size )
{
mCompileError = true;
Expand Down

0 comments on commit cb24984

Please sign in to comment.