You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
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/
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user