Merge pull request #30823 from Paulb23/issue_29500_syntax_highlighter_leak
Fix memory leaks with SyntaxHighlighters
This commit is contained in:
commit
b6ab5b5e2b
@ -2088,16 +2088,18 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
|
|||||||
}
|
}
|
||||||
ERR_FAIL_COND_V(!se, false);
|
ERR_FAIL_COND_V(!se, false);
|
||||||
|
|
||||||
bool highlighter_set = false;
|
if (p_resource->get_class_name() != StringName("VisualScript")) {
|
||||||
for (int i = 0; i < syntax_highlighters_func_count; i++) {
|
bool highlighter_set = false;
|
||||||
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
|
for (int i = 0; i < syntax_highlighters_func_count; i++) {
|
||||||
se->add_syntax_highlighter(highlighter);
|
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
|
||||||
|
se->add_syntax_highlighter(highlighter);
|
||||||
|
|
||||||
if (script != NULL && !highlighter_set) {
|
if (script != NULL && !highlighter_set) {
|
||||||
List<String> languages = highlighter->get_supported_languages();
|
List<String> languages = highlighter->get_supported_languages();
|
||||||
if (languages.find(script->get_language()->get_name())) {
|
if (languages.find(script->get_language()->get_name())) {
|
||||||
se->set_syntax_highlighter(highlighter);
|
se->set_syntax_highlighter(highlighter);
|
||||||
highlighter_set = true;
|
highlighter_set = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1819,6 +1819,15 @@ ScriptTextEditor::ScriptTextEditor() {
|
|||||||
code_editor->get_text_edit()->set_drag_forwarding(this);
|
code_editor->get_text_edit()->set_drag_forwarding(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptTextEditor::~ScriptTextEditor() {
|
||||||
|
for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
|
||||||
|
if (E->get() != NULL) {
|
||||||
|
memdelete(E->get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
highlighters.clear();
|
||||||
|
}
|
||||||
|
|
||||||
static ScriptEditorBase *create_editor(const RES &p_resource) {
|
static ScriptEditorBase *create_editor(const RES &p_resource) {
|
||||||
|
|
||||||
if (Object::cast_to<Script>(*p_resource)) {
|
if (Object::cast_to<Script>(*p_resource)) {
|
||||||
|
@ -231,6 +231,7 @@ public:
|
|||||||
virtual void validate();
|
virtual void validate();
|
||||||
|
|
||||||
ScriptTextEditor();
|
ScriptTextEditor();
|
||||||
|
~ScriptTextEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCRIPT_TEXT_EDITOR_H
|
#endif // SCRIPT_TEXT_EDITOR_H
|
||||||
|
@ -695,5 +695,14 @@ TextEditor::TextEditor() {
|
|||||||
code_editor->get_text_edit()->set_drag_forwarding(this);
|
code_editor->get_text_edit()->set_drag_forwarding(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditor::~TextEditor() {
|
||||||
|
for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
|
||||||
|
if (E->get() != NULL) {
|
||||||
|
memdelete(E->get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
highlighters.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditor::validate() {
|
void TextEditor::validate() {
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,7 @@ public:
|
|||||||
static void register_editor();
|
static void register_editor();
|
||||||
|
|
||||||
TextEditor();
|
TextEditor();
|
||||||
|
~TextEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEXT_EDITOR_H
|
#endif // TEXT_EDITOR_H
|
||||||
|
Loading…
Reference in New Issue
Block a user