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/cube_grid_theme_editor_plugin.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'editor/plugins/cube_grid_theme_editor_plugin.cpp') diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/cube_grid_theme_editor_plugin.cpp index 1fcd514b3..84faa8a26 100644 --- a/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -72,10 +72,10 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, Node *child = p_scene->get_child(i); - if (!child->cast_to()) { + if (!Object::cast_to(child)) { if (child->get_child_count() > 0) { child = child->get_child(0); - if (!child->cast_to()) { + if (!Object::cast_to(child)) { continue; } @@ -83,7 +83,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, continue; } - MeshInstance *mi = child->cast_to(); + MeshInstance *mi = Object::cast_to(child); Ref mesh = mi->get_mesh(); if (mesh.is_null()) continue; @@ -103,10 +103,10 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (!child2->cast_to()) + if (!Object::cast_to(child2)) continue; - StaticBody *sb = child2->cast_to(); + StaticBody *sb = Object::cast_to(child2); List shapes; sb->get_shape_owners(&shapes); @@ -140,9 +140,9 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref p_library, Ref navmesh; for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (!child2->cast_to()) + if (!Object::cast_to(child2)) continue; - NavigationMeshInstance *sb = child2->cast_to(); + NavigationMeshInstance *sb = Object::cast_to(child2); navmesh = sb->get_navigation_mesh(); if (!navmesh.is_null()) break; @@ -341,8 +341,8 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) { void MeshLibraryEditorPlugin::edit(Object *p_node) { - if (p_node && p_node->cast_to()) { - theme_editor->edit(p_node->cast_to()); + if (Object::cast_to(p_node)) { + theme_editor->edit(Object::cast_to(p_node)); theme_editor->show(); } else theme_editor->hide(); -- cgit v1.2.3-70-g09d2