summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2023-08-09 21:27:58 -0500
committerAaron Franke <arnfranke@yahoo.com>2023-09-15 18:40:02 -0500
commitf95f2d1149ad68cd4efb4d19e662e0eea0125b26 (patch)
tree7f16ae2ef1190d83f8792846932d2864f7d0c20c
parent5f1e56ff26be4070496aa51095b9ac2f2b4f4ed8 (diff)
downloadredot-engine-f95f2d1149ad68cd4efb4d19e662e0eea0125b26.tar.gz
Limit mesh complexity in LOD generation to prevent crashing
-rw-r--r--scene/resources/importer_mesh.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index a65a75d878..8768cd7c2a 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);