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/ --- scene/animation/animation_player.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scene/animation/animation_player.cpp') diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 3acb11541..b94115775 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -251,9 +251,9 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id(); int bone_idx = -1; - if (a->track_get_path(i).get_property() && child->cast_to()) { + if (a->track_get_path(i).get_property() && Object::cast_to(child)) { - bone_idx = child->cast_to()->find_bone(a->track_get_path(i).get_property()); + bone_idx = Object::cast_to(child)->find_bone(a->track_get_path(i).get_property()); if (bone_idx == -1) { continue; @@ -280,14 +280,14 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { p_anim->node_cache[i]->path = a->track_get_path(i); p_anim->node_cache[i]->node = child; p_anim->node_cache[i]->resource = resource; - p_anim->node_cache[i]->node_2d = child->cast_to(); + p_anim->node_cache[i]->node_2d = Object::cast_to(child); if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) { // special cases and caches for transform tracks // cache spatial - p_anim->node_cache[i]->spatial = child->cast_to(); + p_anim->node_cache[i]->spatial = Object::cast_to(child); // cache skeleton - p_anim->node_cache[i]->skeleton = child->cast_to(); + p_anim->node_cache[i]->skeleton = Object::cast_to(child); if (p_anim->node_cache[i]->skeleton) { StringName bone_name = a->track_get_path(i).get_property(); -- cgit v1.2.3-70-g09d2