diff options
author | bitsawer <sawerduster@gmail.com> | 2023-01-19 22:06:59 +0200 |
---|---|---|
committer | bitsawer <sawerduster@gmail.com> | 2023-01-19 22:06:59 +0200 |
commit | 6f57aae0ab6234afe0e6ab5f2566ae706adddc4e (patch) | |
tree | 960213396187f20f9eb7cd886aa6d2ad95453e6a /servers/rendering | |
parent | 88cbd5d42266b57e9ca8a0727640082fb303cef3 (diff) |
Fix shader preprocessor memory leak
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/shader_preprocessor.cpp | 14 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.h | 3 |
2 files changed, 7 insertions, 10 deletions
diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index 40c8acffe5..ccbf5defa2 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -1081,21 +1081,17 @@ ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_bo return define; } -void ShaderPreprocessor::clear() { - if (state_owner && state != nullptr) { +void ShaderPreprocessor::clear_state() { + if (state != nullptr) { for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) { memdelete(E->get()); } - - memdelete(state); + state->defines.clear(); } - state_owner = false; state = nullptr; } Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, String &r_result) { - clear(); - output.clear(); state = p_state; @@ -1242,6 +1238,9 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen } } } + + clear_state(); + return err; } @@ -1273,5 +1272,4 @@ ShaderPreprocessor::ShaderPreprocessor() { } ShaderPreprocessor::~ShaderPreprocessor() { - clear(); } diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index f5902c64ca..6e5533c575 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -167,7 +167,6 @@ private: private: LocalVector<char32_t> output; State *state = nullptr; - bool state_owner = false; private: static bool is_char_word(char32_t p_char); @@ -211,7 +210,7 @@ private: static Define *create_define(const String &p_body); - void clear(); + void clear_state(); Error preprocess(State *p_state, const String &p_code, String &r_result); |