From f1ba63e09220274383e756b51cd6aac38e09647f Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Thu, 21 Oct 2021 13:21:41 -0700 Subject: [PATCH] Fix EditorSettings crashes due to nullptr dereference Fixes #45979 Noted a few places in this file that would have similar errors, so any access to the EditorSettings singleton has had a check added. --- editor/editor_settings.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 37a531299ff..4846fd64780 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -1051,6 +1051,8 @@ void EditorSettings::set_initial_value(const StringName &p_setting, const Varian } Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) { + ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet."); + Variant ret = p_default; if (EditorSettings::get_singleton()->has_setting(p_setting)) { ret = EditorSettings::get_singleton()->get(p_setting); @@ -1067,7 +1069,7 @@ Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_re } Variant _EDITOR_GET(const String &p_setting) { - ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_setting), Variant()); + ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant()); return EditorSettings::get_singleton()->get(p_setting); } @@ -1422,9 +1424,7 @@ void EditorSettings::get_shortcut_list(List *r_shortcuts) { } Ref ED_GET_SHORTCUT(const String &p_path) { - if (!EditorSettings::get_singleton()) { - return nullptr; - } + ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet."); Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); @@ -1434,6 +1434,8 @@ Ref ED_GET_SHORTCUT(const String &p_path) { } void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode) { + ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet."); + Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + "."); @@ -1444,6 +1446,8 @@ void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_k } void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes) { + ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet."); + Ref sc = EditorSettings::get_singleton()->get_shortcut(p_path); ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path + ".");