summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorSean Kim <seanctkim@gmail.com>2021-10-21 13:21:41 -0700
committerRĂ©mi Verschelde <remi@verschelde.fr>2022-07-31 13:01:38 +0200
commitf1ba63e09220274383e756b51cd6aac38e09647f (patch)
tree5ca8f240399cd537e6c7ab6fd8a2e996c119d648 /editor
parent14445c96abaa3ebea8ac4070532591a745d46994 (diff)
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.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_settings.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 37a531299f..4846fd6478 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<String> *r_shortcuts) {
}
Ref<Shortcut> 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<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
@@ -1434,6 +1434,8 @@ Ref<Shortcut> 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<Shortcut> 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<Shortcut> 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 + ".");