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 d7b95f4 commit e1b25f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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 @@ -508,6 +508,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
8 changes: 7 additions & 1 deletion RenderSystems/GL3Plus/src/GLSL/OgreGLSLPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,4 +1442,10 @@ namespace Ogre {
return retval.Buffer;
}

} // namespace Ogre
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
3 changes: 1 addition & 2 deletions RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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 @@ -184,7 +183,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

0 comments on commit e1b25f3

Please sign in to comment.