From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: Convert Object::cast_to() to the static version Currently we rely on some undefined behavior when Object->cast_to() gets called with a Null pointer. This used to work fine with GCC < 6 but newer versions of GCC remove all codepaths in which the this pointer is Null. However, the non-static cast_to() was supposed to be null safe. This patch makes cast_to() Null safe and removes the now redundant Null checks where they existed. It is explained in this article: https://www.viva64.com/en/b/0226/ --- editor/plugins/animation_player_editor_plugin.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'editor/plugins/animation_player_editor_plugin.cpp') diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index ecae272b6..a1fec795f 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -656,8 +656,8 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) { return; Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]); - if (n && n->cast_to() && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { - player = n->cast_to(); + if (Object::cast_to(n) && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) { + player = Object::cast_to(n); _update_player(); show(); set_process(true); @@ -737,9 +737,9 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { if (current != "") { Ref anim = player->get_animation(current); - ERR_FAIL_COND(!anim->cast_to()) + ERR_FAIL_COND(!Object::cast_to(*anim)) - RES current_res = RES(anim->cast_to()); + RES current_res = RES(Object::cast_to(*anim)); _animation_save_in_path(current_res, p_file); } @@ -1461,7 +1461,7 @@ void AnimationPlayerEditorPlugin::edit(Object *p_object) { anim_editor->set_undo_redo(&get_undo_redo()); if (!p_object) return; - anim_editor->edit(p_object->cast_to()); + anim_editor->edit(Object::cast_to(p_object)); } bool AnimationPlayerEditorPlugin::handles(Object *p_object) const { -- cgit v1.2.3-70-g09d2