summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-25 23:12:35 +0200
committerGitHub <noreply@github.com>2019-07-25 23:12:35 +0200
commitb6ab5b5e2bbdc6881f65c56a2c4ab39edbd6a87b (patch)
tree94a96d89559afa057e86a8c4740a1f958b6c837b
parent3a68b241718a6bfef68e6e9916ec152b2615fea2 (diff)
parente51aa14208b6c0b87191b046ace6b9b59678969f (diff)
Merge pull request #30823 from Paulb23/issue_29500_syntax_highlighter_leak
Fix memory leaks with SyntaxHighlighters
-rw-r--r--editor/plugins/script_editor_plugin.cpp22
-rw-r--r--editor/plugins/script_text_editor.cpp9
-rw-r--r--editor/plugins/script_text_editor.h1
-rw-r--r--editor/plugins/text_editor.cpp9
-rw-r--r--editor/plugins/text_editor.h1
5 files changed, 32 insertions, 10 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index d999f3189e..9cf889c5b0 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -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);
- bool highlighter_set = false;
- for (int i = 0; i < syntax_highlighters_func_count; i++) {
- SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
- se->add_syntax_highlighter(highlighter);
-
- if (script != NULL && !highlighter_set) {
- List<String> languages = highlighter->get_supported_languages();
- if (languages.find(script->get_language()->get_name())) {
- se->set_syntax_highlighter(highlighter);
- highlighter_set = true;
+ if (p_resource->get_class_name() != StringName("VisualScript")) {
+ bool highlighter_set = false;
+ for (int i = 0; i < syntax_highlighters_func_count; i++) {
+ SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
+ se->add_syntax_highlighter(highlighter);
+
+ if (script != NULL && !highlighter_set) {
+ List<String> languages = highlighter->get_supported_languages();
+ if (languages.find(script->get_language()->get_name())) {
+ se->set_syntax_highlighter(highlighter);
+ highlighter_set = true;
+ }
}
}
}
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 438621115b..07303da2ff 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1819,6 +1819,15 @@ ScriptTextEditor::ScriptTextEditor() {
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) {
if (Object::cast_to<Script>(*p_resource)) {
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 9a2a514a6e..4dbade472c 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -231,6 +231,7 @@ public:
virtual void validate();
ScriptTextEditor();
+ ~ScriptTextEditor();
};
#endif // SCRIPT_TEXT_EDITOR_H
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index fae88f4eb7..34d8e6aff5 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -695,5 +695,14 @@ TextEditor::TextEditor() {
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() {
}
diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h
index ae0c0bcf93..3a330576ae 100644
--- a/editor/plugins/text_editor.h
+++ b/editor/plugins/text_editor.h
@@ -154,6 +154,7 @@ public:
static void register_editor();
TextEditor();
+ ~TextEditor();
};
#endif // TEXT_EDITOR_H