From 7e70e071e9a0448edd1d78610af41e5a35cc5dac Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 14 Aug 2023 18:05:22 +0800 Subject: [PATCH] FIX: loading stl with NaN points crashes Avoid loading NaN points. Jira: STUDIO-3889 Change-Id: I8c00f24e0ae1ba3b637e5d9bb13de93b1b4e77ba (cherry picked from commit 0d244c7f65b913922ca4fad59d93fd80725f2e49) --- src/admesh/stlinit.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/admesh/stlinit.cpp b/src/admesh/stlinit.cpp index f1be4ac77c..095f7f715a 100644 --- a/src/admesh/stlinit.cpp +++ b/src/admesh/stlinit.cpp @@ -237,7 +237,17 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor } #endif - // Write the facet into memory. + // Write the facet into memory if none of facet vertices is NAN. + bool someone_is_nan = false; + for (size_t j = 0; j < 3; ++j) { + if (isnan(facet.vertex[j](0)) || isnan(facet.vertex[j](1)) || isnan(facet.vertex[j](2))) { + someone_is_nan = true; + break; + } + } + if(someone_is_nan) + continue; + stl->facet_start[i] = facet; stl_facet_stats(stl, facet, first); }