From a349dbd76254abe2d85db743269037ff60057ee1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 21 Jul 2022 19:48:08 +0200 Subject: [PATCH] Fix potential crash. --- modules/text_editor/text_file_editor.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/text_editor/text_file_editor.cpp b/modules/text_editor/text_file_editor.cpp index 931a4c3c5..7a08dad27 100644 --- a/modules/text_editor/text_file_editor.cpp +++ b/modules/text_editor/text_file_editor.cpp @@ -271,11 +271,15 @@ TextEditorVanillaEditor *TextFileEditor::open_in_vanillaeditor(const String &pat FileAccess *current_file = FileAccess::open(path, FileAccess::READ); String current_content = ""; - current_content = current_file->get_as_utf8_string(); - OS::DateTime last_modified = OS::get_singleton()->get_datetime_from_unix_time(current_file->get_modified_time(path)); + OS::DateTime last_modified; - current_file->close(); - memdelete(current_file); + if (current_file) { + current_content = current_file->get_as_utf8_string(); + last_modified = OS::get_singleton()->get_datetime_from_unix_time(current_file->get_modified_time(path)); + + current_file->close(); + memdelete(current_file); + } editor->new_file_open(current_content, last_modified, current_file_path); update_list();