diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 22:58:51 +0200 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 23:08:24 +0200 |
commit | cacced7e507f7603bacc03ae2616e58f0ede122a (patch) | |
tree | 7af89373e86cd1a7af6ea04e10280084cabb7144 /scene/2d/parallax_layer.cpp | |
parent | 4aa2c18cb428ffde05c67987926736a9ca62703b (diff) |
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/
Diffstat (limited to 'scene/2d/parallax_layer.cpp')
-rw-r--r-- | scene/2d/parallax_layer.cpp | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index debdc22b65..40d688b708 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -36,11 +36,8 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { motion_scale = p_scale; - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); - if (is_inside_tree() && pb) { + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); + if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); set_base_offset_and_scale(ofs, scale); @@ -56,11 +53,8 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { motion_offset = p_offset; - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); - if (is_inside_tree() && pb) { + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); + if (pb && is_inside_tree()) { Vector2 ofs = pb->get_final_offset(); float scale = pb->get_scroll_scale(); set_base_offset_and_scale(ofs, scale); @@ -74,10 +68,7 @@ Size2 ParallaxLayer::get_motion_offset() const { void ParallaxLayer::_update_mirroring() { - if (!get_parent()) - return; - - ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); if (pb) { RID c = pb->get_world_2d()->get_canvas(); @@ -139,7 +130,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_sc String ParallaxLayer::get_configuration_warning() const { - if (!get_parent() || !get_parent()->cast_to<ParallaxBackground>()) { + if (!Object::cast_to<ParallaxBackground>(get_parent())) { return TTR("ParallaxLayer node only works when set as child of a ParallaxBackground node."); } |