From 8ed4af259a3c940b3fa249307f6cc7366e1ceb04 Mon Sep 17 00:00:00 2001 From: RealMadvicius Date: Sat, 7 Oct 2023 11:03:13 +0200 Subject: [PATCH] Fix crash when clicking on "Interpolation Mode" with nonexistent node path issue reference [https://github.com/godotengine/godot/issues/81769] - adding a nullptr check on a Node pointer obtained from get_node(NodePath) in case it is null now we wont execute the next instruction > ClassDB::get_property_info(nd->get_class(), prop, &prop_info); Which then prevents the crash (cherry picked from commit e7a35d152104c14ba89861a6ead892c4f65d9f5d) --- editor/animation_track_editor.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 24a6d89118d..369330dd16c 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2694,14 +2694,21 @@ void AnimationTrackEdit::gui_input(const Ref &p_event) { AnimationPlayer *ap = ape->get_player(); if (ap) { NodePath npath = animation->track_get_path(track); - Node *nd = ap->get_node(ap->get_root())->get_node(NodePath(npath.get_concatenated_names())); - StringName prop = npath.get_concatenated_subnames(); - PropertyInfo prop_info; - ClassDB::get_property_info(nd->get_class(), prop, &prop_info); - bool is_angle = prop_info.type == Variant::FLOAT && prop_info.hint_string.find("radians") != -1; - if (is_angle) { - menu->add_icon_item(get_theme_icon(SNAME("InterpLinearAngle"), SNAME("EditorIcons")), TTR("Linear Angle"), MENU_INTERPOLATION_LINEAR_ANGLE); - menu->add_icon_item(get_theme_icon(SNAME("InterpCubicAngle"), SNAME("EditorIcons")), TTR("Cubic Angle"), MENU_INTERPOLATION_CUBIC_ANGLE); + Node *a_ap_root_node = ap->get_node(ap->get_root()); + Node *nd = nullptr; + // We must test that we have a valid a_ap_root_node before trying to access its content to init the nd Node. + if (a_ap_root_node) { + nd = a_ap_root_node->get_node(NodePath(npath.get_concatenated_names())); + } + if (nd) { + StringName prop = npath.get_concatenated_subnames(); + PropertyInfo prop_info; + ClassDB::get_property_info(nd->get_class(), prop, &prop_info); + bool is_angle = prop_info.type == Variant::FLOAT && prop_info.hint_string.find("radians") != -1; + if (is_angle) { + menu->add_icon_item(get_theme_icon(SNAME("InterpLinearAngle"), SNAME("EditorIcons")), TTR("Linear Angle"), MENU_INTERPOLATION_LINEAR_ANGLE); + menu->add_icon_item(get_theme_icon(SNAME("InterpCubicAngle"), SNAME("EditorIcons")), TTR("Cubic Angle"), MENU_INTERPOLATION_CUBIC_ANGLE); + } } } }