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/resources/packed_scene.cpp | |
parent | 4aa2c18cb428ffde05c67987926736a9ca62703b (diff) | |
download | redot-engine-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.gz |
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/resources/packed_scene.cpp')
-rw-r--r-- | scene/resources/packed_scene.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index d7ea675a47..3ce44e2c31 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -151,18 +151,18 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //print_line("created"); //node belongs to this scene and must be created Object *obj = ClassDB::instance(snames[n.type]); - if (!obj || !obj->cast_to<Node>()) { + if (!Object::cast_to<Node>(obj)) { if (obj) { memdelete(obj); obj = NULL; } WARN_PRINT(String("Warning node of type " + snames[n.type].operator String() + " does not exist.").ascii().get_data()); if (n.parent >= 0 && n.parent < nc && ret_nodes[n.parent]) { - if (ret_nodes[n.parent]->cast_to<Spatial>()) { + if (Object::cast_to<Spatial>(ret_nodes[n.parent])) { obj = memnew(Spatial); - } else if (ret_nodes[n.parent]->cast_to<Control>()) { + } else if (Object::cast_to<Control>(ret_nodes[n.parent])) { obj = memnew(Control); - } else if (ret_nodes[n.parent]->cast_to<Node2D>()) { + } else if (Object::cast_to<Node2D>(ret_nodes[n.parent])) { obj = memnew(Node2D); } } @@ -172,7 +172,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } } - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); } else { print_line("wtf class is disabled for: " + itos(n.type)); @@ -754,7 +754,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName // only connections that originate or end into main saved scene are saved // everything else is discarded - Node *target = c.target->cast_to<Node>(); + Node *target = Object::cast_to<Node>(c.target); if (!target) { continue; |