diff options
| author | Hein-Pieter van Braam | 2017-08-24 22:58:51 +0200 |
|---|---|---|
| committer | Hein-Pieter van Braam | 2017-08-24 23:08:24 +0200 |
| commit | cacced7e507f7603bacc03ae2616e58f0ede122a (patch) | |
| tree | 7af89373e86cd1a7af6ea04e10280084cabb7144 /editor/plugins/cube_grid_theme_editor_plugin.cpp | |
| parent | 4aa2c18cb428ffde05c67987926736a9ca62703b (diff) | |
| download | godot-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.gz godot-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.zst godot-cacced7e507f7603bacc03ae2616e58f0ede122a.zip | |
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 'editor/plugins/cube_grid_theme_editor_plugin.cpp')
| -rw-r--r-- | editor/plugins/cube_grid_theme_editor_plugin.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
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<MeshLibrary> p_library, Node *child = p_scene->get_child(i); - if (!child->cast_to<MeshInstance>()) { + if (!Object::cast_to<MeshInstance>(child)) { if (child->get_child_count() > 0) { child = child->get_child(0); - if (!child->cast_to<MeshInstance>()) { + if (!Object::cast_to<MeshInstance>(child)) { continue; } @@ -83,7 +83,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, continue; } - MeshInstance *mi = child->cast_to<MeshInstance>(); + MeshInstance *mi = Object::cast_to<MeshInstance>(child); Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_null()) continue; @@ -103,10 +103,10 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (!child2->cast_to<StaticBody>()) + if (!Object::cast_to<StaticBody>(child2)) continue; - StaticBody *sb = child2->cast_to<StaticBody>(); + StaticBody *sb = Object::cast_to<StaticBody>(child2); List<uint32_t> shapes; sb->get_shape_owners(&shapes); @@ -140,9 +140,9 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, Ref<NavigationMesh> navmesh; for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (!child2->cast_to<NavigationMeshInstance>()) + if (!Object::cast_to<NavigationMeshInstance>(child2)) continue; - NavigationMeshInstance *sb = child2->cast_to<NavigationMeshInstance>(); + NavigationMeshInstance *sb = Object::cast_to<NavigationMeshInstance>(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<MeshLibrary>()) { - theme_editor->edit(p_node->cast_to<MeshLibrary>()); + if (Object::cast_to<MeshLibrary>(p_node)) { + theme_editor->edit(Object::cast_to<MeshLibrary>(p_node)); theme_editor->show(); } else theme_editor->hide(); |
