Fix shader preprocessor memory leak

This commit is contained in:
bitsawer 2023-01-19 22:06:59 +02:00
parent 88cbd5d422
commit 6f57aae0ab
2 changed files with 7 additions and 10 deletions

View File

@ -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();
}

View File

@ -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);