From a3a7f97e2858f1036ece7097998db465be0cc18d Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Sun, 19 May 2019 17:22:03 +0200 Subject: [PATCH] check for already allocated memory --- xs/src/admesh/util.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xs/src/admesh/util.c b/xs/src/admesh/util.c index 655820cc0..44e23cc03 100644 --- a/xs/src/admesh/util.c +++ b/xs/src/admesh/util.c @@ -189,8 +189,20 @@ void stl_transform(stl_file const *stl_src, stl_file *stl_dst, float const *traf int i_face, i_vertex, i, j; if (stl_src->error || stl_dst->error) return; - stl_dst->stats.number_of_facets = stl_src->stats.number_of_facets; - stl_allocate(stl_dst); + + if (stl_dst->stats.facets_malloced != stl_src->stats.number_of_facets) + { + stl_dst->stats.number_of_facets = stl_src->stats.number_of_facets; + if (stl_dst->stats.facets_malloced > 0) + { + stl_reallocate(stl_dst); + } + else + { + stl_allocate(stl_dst); + } + } + printf("Supplied trafo: %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, %.1f\n", trafo3x4[0], trafo3x4[1],