Skip to content

Commit fcbd713

Browse files
committed
Append .stl to path in the default writer.
1 parent 094382b commit fcbd713

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/mesh.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,27 @@ int _default_write(void *self, char *path) {
3131
int rc = -1;
3232
mesh_t *mesh = (mesh_t*)self;
3333
stl_object *stl = NULL;
34-
klist_t(poly) *polys = mesh->to_polygons(mesh);
35-
check(polys != NULL, "Failed to get polygons from mesh %p", mesh);
34+
klist_t(poly) *polys = NULL;
35+
char *out_path = NULL;
36+
37+
check_mem(out_path = calloc(1, strlen(path) + strlen(".stl") + 1));
38+
check((polys = mesh->to_polygons(mesh)) != NULL, "Failed to get polygons from mesh %p", mesh);
39+
3640

3741
// The default output format is STL
42+
// The output path will always end in ".stl" when using this writer
43+
rc = sprintf(out_path, "%s.stl", path);
44+
check(rc != -1, "Failed to generate output path.");
3845
stl = stl_from_polys(polys);
3946
check(stl != NULL, "Failed to generate STL object for write.");
40-
rc = stl_write_file(stl, path);
47+
rc = stl_write_file(stl, out_path);
4148

49+
if(out_path != NULL) free(out_path);
4250
if(stl != NULL) stl_free(stl);
4351
if(polys != NULL) kl_destroy(poly, polys);
4452
return rc;
4553
error:
54+
if(out_path != NULL) free(out_path);
4655
if(stl != NULL) stl_free(stl);
4756
if(polys != NULL) kl_destroy(poly, polys);
4857
return -1;

0 commit comments

Comments
 (0)