From 82f7f2c46c023629042d16ada5d5085bd29bb9ad Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 29 Sep 2021 16:59:46 +0800 Subject: [PATCH] Fix crash in headless mode --- scene/3d/mesh_instance_3d.cpp | 2 ++ scene/resources/navigation_mesh.cpp | 2 ++ servers/rendering/rendering_server_default.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 7e7db57af37..28bf468cb71 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -369,6 +369,8 @@ void MeshInstance3D::create_debug_tangents() { for (int i = 0; i < mesh->get_surface_count(); i++) { Array arrays = mesh->surface_get_arrays(i); + ERR_CONTINUE(arrays.size() != Mesh::ARRAY_MAX); + Vector verts = arrays[Mesh::ARRAY_VERTEX]; Vector norms = arrays[Mesh::ARRAY_NORMAL]; if (norms.size() == 0) { diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 00cee9269b9..11e5eb1c310 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -41,6 +41,8 @@ void NavigationMesh::create_from_mesh(const Ref &p_mesh) { continue; } Array arr = p_mesh->surface_get_arrays(i); + ERR_CONTINUE(arr.size() != Mesh::ARRAY_MAX); + Vector varr = arr[Mesh::ARRAY_VERTEX]; Vector iarr = arr[Mesh::ARRAY_INDEX]; if (varr.size() == 0 || iarr.size() == 0) { diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index bed6ade1f66..62390f9d4d1 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -45,6 +45,9 @@ int RenderingServerDefault::changes = 0; /* FREE */ void RenderingServerDefault::_free(RID p_rid) { + if (unlikely(p_rid.is_null())) { + return; + } if (RSG::storage->free(p_rid)) { return; }