You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Fix shader preprocessor memory leak
This commit is contained in:
@@ -1081,21 +1081,17 @@ ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_bo
|
|||||||
return define;
|
return define;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderPreprocessor::clear() {
|
void ShaderPreprocessor::clear_state() {
|
||||||
if (state_owner && state != nullptr) {
|
if (state != nullptr) {
|
||||||
for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) {
|
for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) {
|
||||||
memdelete(E->get());
|
memdelete(E->get());
|
||||||
}
|
}
|
||||||
|
state->defines.clear();
|
||||||
memdelete(state);
|
|
||||||
}
|
}
|
||||||
state_owner = false;
|
|
||||||
state = nullptr;
|
state = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, String &r_result) {
|
Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, String &r_result) {
|
||||||
clear();
|
|
||||||
|
|
||||||
output.clear();
|
output.clear();
|
||||||
|
|
||||||
state = p_state;
|
state = p_state;
|
||||||
@@ -1242,6 +1238,9 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear_state();
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1273,5 +1272,4 @@ ShaderPreprocessor::ShaderPreprocessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderPreprocessor::~ShaderPreprocessor() {
|
ShaderPreprocessor::~ShaderPreprocessor() {
|
||||||
clear();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
LocalVector<char32_t> output;
|
LocalVector<char32_t> output;
|
||||||
State *state = nullptr;
|
State *state = nullptr;
|
||||||
bool state_owner = false;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool is_char_word(char32_t p_char);
|
static bool is_char_word(char32_t p_char);
|
||||||
@@ -211,7 +210,7 @@ private:
|
|||||||
|
|
||||||
static Define *create_define(const String &p_body);
|
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);
|
Error preprocess(State *p_state, const String &p_code, String &r_result);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user