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/tile_set_editor_plugin.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'editor/plugins/tile_set_editor_plugin.cpp') diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 8396b4d412..7637ce97fc 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -43,7 +43,7 @@ void TileSetEditor::_import_node(Node *p_node, Ref p_library) { Node *child = p_node->get_child(i); - if (!child->cast_to()) { + if (!Object::cast_to(child)) { if (child->get_child_count() > 0) { _import_node(child, p_library); } @@ -51,7 +51,7 @@ void TileSetEditor::_import_node(Node *p_node, Ref p_library) { continue; } - Sprite *mi = child->cast_to(); + Sprite *mi = Object::cast_to(child); Ref texture = mi->get_texture(); Ref normal_map = mi->get_normal_map(); Ref material = mi->get_material(); @@ -99,18 +99,18 @@ void TileSetEditor::_import_node(Node *p_node, Ref p_library) { Node *child2 = mi->get_child(j); - if (child2->cast_to()) - nav_poly = child2->cast_to()->get_navigation_polygon(); + if (Object::cast_to(child2)) + nav_poly = Object::cast_to(child2)->get_navigation_polygon(); - if (child2->cast_to()) - occluder = child2->cast_to()->get_occluder_polygon(); + if (Object::cast_to(child2)) + occluder = Object::cast_to(child2)->get_occluder_polygon(); - if (!child2->cast_to()) + if (!Object::cast_to(child2)) continue; found_collisions = true; - StaticBody2D *sb = child2->cast_to(); + StaticBody2D *sb = Object::cast_to(child2); List shapes; sb->get_shape_owners(&shapes); @@ -268,8 +268,8 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { void TileSetEditorPlugin::edit(Object *p_node) { - if (p_node && p_node->cast_to()) { - tileset_editor->edit(p_node->cast_to()); + if (Object::cast_to(p_node)) { + tileset_editor->edit(Object::cast_to(p_node)); tileset_editor->show(); } else tileset_editor->hide(); -- cgit v1.2.3