star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

commit 8cea8e04dced42bf9807ec79c80bb67aaa4d8462
parent af939e7607d42968d8c0dafc4766cef5a638d1dc
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 17 May 2023 15:37:20 +0200

Fix lifetime management for extrusion arg.

Diffstat:
Msrc/scad.h | 2+-
Msrc/scad_geometry.c | 9+++++++--
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/scad.h b/src/scad.h @@ -381,7 +381,7 @@ scad_geometry_rotate /* Extrude the geometry `geom' using a translation along (`dx', `dy', `dz'). */ SCAD_API res_T scad_geometry_extrude - (const struct scad_geometry* geom, + (struct scad_geometry* geom, const char* name, /* Can be NULL */ const double dxdydz[3], struct scad_geometry** out_geometry); diff --git a/src/scad_geometry.c b/src/scad_geometry.c @@ -1179,7 +1179,7 @@ error: res_T scad_geometry_extrude - (const struct scad_geometry* geom, + (struct scad_geometry* geom, const char* name, const double dxdydz[3], struct scad_geometry** out_geometry) @@ -1193,6 +1193,7 @@ scad_geometry_extrude int ierr = 0; struct scad_geometry* extrude_geom = NULL; struct scad_device* dev = get_device(); + struct scad_geometry* tmp = NULL; struct mem_allocator* allocator = NULL; if(!geom || !dxdydz || !out_geometry) { @@ -1203,7 +1204,10 @@ scad_geometry_extrude ERR(check_device(FUNC_NAME)); allocator = dev->allocator; - gmshModelOccExtrude(geom->gmsh_dimTags, geom->gmsh_dimTags_n, SPLIT3(dxdydz), + /* Need to duplicate geom or deleting out_geometry will delete geom too */ + ERR(scad_geometry_copy(geom, NULL, &tmp)); + + gmshModelOccExtrude(tmp->gmsh_dimTags, tmp->gmsh_dimTags_n, SPLIT3(dxdydz), &tagout, &tagoutn, NULL, 0, NULL, 0, 0, &ierr); get_device()->need_synchro = 1; ERR(gmsh_err_to_res_T(ierr)); @@ -1244,6 +1248,7 @@ error: SCAD(geometry_ref_put(extrude_geom)); extrude_geom = NULL; } + if(tmp) SCAD(geometry_ref_put(tmp)); goto exit; }