city_generator2

Generated conformal 3D meshes representing a city
git clone git://git.meso-star.fr/city_generator2.git
Log | Files | Refs | README | LICENSE

commit 4429f78bade74fd4f33bc7c9942f2d290aff5c2a
parent 905ec8434dd5a0007dbed2d0735afa263ccc023e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 10 Mar 2023 14:26:19 +0100

Fix geometry not properly released in ground cad

Diffstat:
Msrc/cg_ground.c | 60++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 22 deletions(-)

diff --git a/src/cg_ground.c b/src/cg_ground.c @@ -24,6 +24,16 @@ #include <rsys/str.h> #include <star/scad.h> +#define GDEL(Tgt) \ + if(Tgt) SCAD(geometry_delete(Tgt)); \ + /* To avoid double delete, set to NULL after deletion */ \ + Tgt = NULL + +#define GMV(Idx) \ + ground->boundary[Idx] = surface; \ + /* To avoid double delete, set to NULL after deletion */ \ + surface = NULL + res_T ground_build_cad (struct mem_allocator* allocator, @@ -57,8 +67,9 @@ ground_build_cad ERR(scad_geometry_boundary(NULL, &ground->box, 1, &bound)); ERR(scad_geometry_explode(bound, NULL, &list, &count)); + ASSERT(count == 6); - ground->boundary = MEM_CALLOC(allocator, 6, sizeof(struct scad_geometry*)); + ground->boundary = MEM_CALLOC(allocator, count, sizeof(struct scad_geometry*)); for (i = 0; i < count; i++) { double center[3]; @@ -72,42 +83,45 @@ ground_build_cad ERR(scad_geometry_normal(list[i], center, N, NULL, &surface)); if (N[0] == 0 && N[1] == 0 && N[2] == -1) { - ERR(scad_geometry_copy(surface, "ground_B_bottom", &ground->boundary[0])); + ERR(scad_geometry_rename(surface, "ground_B_bottom")); + GMV(0); } - - if (N[0] == 0 && N[1] == 0 && N[2] == 1) { + else if (N[0] == 0 && N[1] == 0 && N[2] == 1) { ERR(scad_cut_geometries("ground_B_top", &surface, 1, ground->footprints, ground->footprints_count, &ground->boundary[1])); + GDEL(surface); } - - if (N[0] == -1 && N[1] == 0 && N[2] == 0) { - ERR(scad_geometry_copy(surface, "ground_B_lateral_0", &ground->boundary[2])); + else if (N[0] == -1 && N[1] == 0 && N[2] == 0) { + ERR(scad_geometry_rename(surface, "ground_B_lateral_0")); + GMV(2); } - - if (N[0] == 1 && N[1] == 0 && N[2] == 0) { - ERR(scad_geometry_copy(surface, "ground_B_lateral_1", &ground->boundary[3])); + else if (N[0] == 1 && N[1] == 0 && N[2] == 0) { + ERR(scad_geometry_rename(surface, "ground_B_lateral_1")); + GMV(3); } - - if (N[0] == 0 && N[1] == -1 && N[2] == 0) { - ERR(scad_geometry_copy(surface, "ground_B_lateral_2", &ground->boundary[4])); + else if (N[0] == 0 && N[1] == -1 && N[2] == 0) { + ERR(scad_geometry_rename(surface, "ground_B_lateral_2")); + GMV(4); } - - if (N[0] == 0 && N[1] == 1 && N[2] == 0) { - ERR(scad_geometry_copy(surface, "ground_B_lateral_3", &ground->boundary[5])); + else if (N[0] == 0 && N[1] == 1 && N[2] == 0) { + ERR(scad_geometry_rename(surface, "ground_B_lateral_3")); + GMV(5); } + else FATAL("Wrong ground box boundary."); } exit: for (i = 0; i < count; i++) { - scad_geometry_delete(list[i]); + GDEL(list[i]); } - if (surface) scad_geometry_delete(surface); MEM_RM(allocator, list); - if (bound) SCAD(geometry_delete(bound)); + GDEL(surface); + GDEL(bound); return res; error: goto exit; } +#undef GMV res_T ground_export_stl(const struct ground* ground, const int binary) @@ -157,14 +171,16 @@ ground_clear struct ground* ground) { size_t i; - SCAD(geometry_delete(ground->box)); + GDEL(ground->box); for(i = 0; i < 6; i++) { - SCAD(geometry_delete(ground->boundary[i])); + GDEL(ground->boundary[i]); } MEM_RM(allocator, ground->boundary); for(i = 0; i < ground->footprints_count; i++) { - SCAD(geometry_delete(ground->footprints[i])); + GDEL(ground->footprints[i]); } MEM_RM(allocator, ground->footprints); } + +#undef GDEL