From 3518801deb3d2e13579bbb73d83d192ffaf46878 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Wed, 9 Aug 2023 21:27:58 -0500 Subject: [PATCH] Limit mesh complexity in LOD generation to prevent crashing (cherry picked from commit f95f2d1149ad68cd4efb4d19e662e0eea0125b26) --- scene/resources/importer_mesh.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index a65a75d8789..8768cd7c2ac 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -475,6 +475,14 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli if (new_index_count == 0 || (new_index_count >= (index_count * 0.75f))) { break; } + if (new_index_count > 5000000) { + // This limit theoretically shouldn't be needed, but it's here + // as an ad-hoc fix to prevent a crash with complex meshes. + // The crash still happens with limit of 6000000, but 5000000 works. + // In the future, identify what's causing that crash and fix it. + WARN_PRINT("Mesh LOD generation failed for mesh " + get_name() + " surface " + itos(i) + ", mesh is too complex. Some automatic LODs were not generated."); + break; + } new_indices.resize(new_index_count);