commit 7b11d562835e2387a1bdb20cec2523f55ec98e29
parent 48fe3f273657bcd71e9e8aeecf2e8dd39e1738d3
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 19 Dec 2022 15:13:26 +0100
BugFix: cad data kept past cad finalize
Diffstat:
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/src/cg_city.c b/src/cg_city.c
@@ -123,26 +123,19 @@ res_T
city_cad_build(struct logger* logger, struct city* city)
{
res_T res = RES_OK;
- struct scad_options options = SCAD_DEFAULT_OPTIONS__;
size_t i;
(void)logger;
- ERR(scad_initialize(logger, NULL, 3));
- options.Mesh.MeshSizeFromPoints = 0;
- ERR(scad_set_options(&options));
-
/* iterate on building */
- for (i=0; i<city->buildings_count; ++i) {
+ for(i=0; i<city->buildings_count; ++i) {
struct building* building = city->buildings + i;
/* create building */
ERR(building->build_cad(building));
ERR(scad_scene_mesh());
ERR(building->export_stl(building, city->binary_export));
- ERR(scad_scene_clear());
}
exit:
- scad_finalize();
return res;
error:
goto exit;
@@ -152,14 +145,9 @@ res_T
city_ground_build(struct logger* logger, struct city* city)
{
res_T res = RES_OK;
- struct scad_options options = SCAD_DEFAULT_OPTIONS__;
size_t i;
(void)logger;
- ERR(scad_initialize(logger, NULL, 3));
- options.Mesh.MeshSizeFromPoints = 0;
- ERR(scad_set_options(&options));
-
city->ground.footprints_count = city->buildings_count;
city->ground.footprint
= malloc(city->ground.footprints_count * sizeof(*city->ground.footprint));
@@ -168,7 +156,7 @@ city_ground_build(struct logger* logger, struct city* city)
goto error;
}
- for (i = 0; i < city->ground.footprints_count ; ++i) {
+ for(i = 0; i < city->ground.footprints_count ; ++i) {
struct building* building = city->buildings + i;
struct scad_geometry** footprint = city->ground.footprint + i;
/* create building footprint */
@@ -180,7 +168,6 @@ city_ground_build(struct logger* logger, struct city* city)
ERR(ground_export_stl(&city->ground, city->binary_export));
exit:
- scad_finalize();
return res;
error:
goto exit;
diff --git a/src/cg_main.c b/src/cg_main.c
@@ -29,6 +29,7 @@
#include <rsys/rsys.h>
#include <rsys/logger.h>
#include <rsys/mem_allocator.h>
+#include <star/scad.h>
char const* constructive_mode_name[CONSTRUCTIVE_MODES_COUNT__] = {
"model0",
@@ -101,6 +102,8 @@ int main
.log_level = CYAML_LOG_WARNING, /* Logging errors and warnings only. */
.flags = CYAML_CFG_DEFAULT,
};
+ struct scad_options options = SCAD_DEFAULT_OPTIONS__;
+ int scad_initialized = 0;
/* init allocator and logger */
ERR(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
@@ -132,6 +135,12 @@ int main
if(args.verbose < 3)
logger_set_stream(&logger, LOG_OUTPUT, NULL, NULL);
+ /* Initialize star-cad */
+ ERR(scad_initialize(&logger, &allocator, args.verbose));
+ scad_initialized = 1;
+ options.Mesh.MeshSizeFromPoints = 0;
+ ERR(scad_set_options(&options));
+
/* Parse city description.
* No semantic validation is done at this stage */
ERR(parse_city(args.city_filename, &allocator, &logger, &config, &parsed_city));
@@ -155,6 +164,7 @@ exit:
if(cg_initialized) city_release(city);
if(parsed_city_initialized) release_parsed_city(&config, parsed_city);
if(logger_initialized) logger_release(&logger);
+ if(scad_initialized) CHK(RES_OK == scad_finalize());
if(allocator_initialized) {
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);