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/2d/sprite.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scene/2d/sprite.cpp') diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 2ec529a16..b7b68d806 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -399,7 +399,7 @@ void ViewportSprite::_notification(int p_what) { Node *n = get_node(viewport_path); ERR_FAIL_COND(!n); - Viewport *vp=n->cast_to(); + Viewport *vp=Object::cast_to(n); ERR_FAIL_COND(!vp); Ref rtt = vp->get_render_target_texture(); @@ -467,7 +467,7 @@ void ViewportSprite::set_viewport_path(const NodePath& p_viewport) { Node *n = get_node(viewport_path); ERR_FAIL_COND(!n); - Viewport *vp=n->cast_to(); + Viewport *vp=Object::cast_to(n); ERR_FAIL_COND(!vp); Ref rtt = vp->get_render_target_texture(); @@ -544,13 +544,13 @@ Rect2 ViewportSprite::get_item_rect() const { String ViewportSprite::get_configuration_warning() const { - if (!has_node(viewport_path) || !get_node(viewport_path) || !get_node(viewport_path)->cast_to()) { + if (!has_node(viewport_path) || !Object::cast_to(get_node(viewport_path))) { return TTR("Path property must point to a valid Viewport node to work. Such Viewport must be set to 'render target' mode."); } else { Node *n = get_node(viewport_path); if (n) { - Viewport *vp = n->cast_to(); + Viewport *vp = Object::cast_to(n); if (!vp->is_set_as_render_target()) { return TTR("The Viewport set in the path property must be set as 'render target' in order for this sprite to work."); -- cgit v1.2.3-70-g09d2