@@ -31,18 +31,27 @@ int _default_write(void *self, char *path) {
31
31
int rc = -1 ;
32
32
mesh_t * mesh = (mesh_t * )self ;
33
33
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
+
36
40
37
41
// 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." );
38
45
stl = stl_from_polys (polys );
39
46
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 );
41
48
49
+ if (out_path != NULL ) free (out_path );
42
50
if (stl != NULL ) stl_free (stl );
43
51
if (polys != NULL ) kl_destroy (poly , polys );
44
52
return rc ;
45
53
error :
54
+ if (out_path != NULL ) free (out_path );
46
55
if (stl != NULL ) stl_free (stl );
47
56
if (polys != NULL ) kl_destroy (poly , polys );
48
57
return -1 ;
0 commit comments