From 62e781b9145e25d15be220b0c6245af05b37c2b3 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Fri, 27 May 2022 19:35:00 +0200 Subject: [PATCH] Fix MultiMeshInstance crash in navmesh baking when MultiMesh Resource is empty Fix MultiMeshInstance crash in navmesh baking when MultiMesh Resource is empty (cherry picked from commit caceceab0819dca9da4ca3c268bc07ded933e332) --- .../navigation/navigation_mesh_generator.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp index 7738ea04d..539a5e912 100644 --- a/modules/navigation/navigation_mesh_generator.cpp +++ b/modules/navigation/navigation_mesh_generator.cpp @@ -170,14 +170,16 @@ void NavigationMeshGenerator::_parse_geometry(const Transform &p_navmesh_xform, if (Object::cast_to(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { MultiMeshInstance *multimesh_instance = Object::cast_to(p_node); Ref multimesh = multimesh_instance->get_multimesh(); - Ref mesh = multimesh->get_mesh(); - if (mesh.is_valid()) { - int n = multimesh->get_visible_instance_count(); - if (n == -1) { - n = multimesh->get_instance_count(); - } - for (int i = 0; i < n; i++) { - _add_mesh(mesh, p_navmesh_xform * multimesh_instance->get_global_transform() * multimesh->get_instance_transform(i), p_vertices, p_indices); + if (multimesh.is_valid()) { + Ref mesh = multimesh->get_mesh(); + if (mesh.is_valid()) { + int n = multimesh->get_visible_instance_count(); + if (n == -1) { + n = multimesh->get_instance_count(); + } + for (int i = 0; i < n; i++) { + _add_mesh(mesh, p_navmesh_xform * multimesh_instance->get_global_transform() * multimesh->get_instance_transform(i), p_vertices, p_indices); + } } } }