diff --git a/xs/src/Surface.hpp b/xs/src/Surface.hpp index 291c3e850..5725e7214 100644 --- a/xs/src/Surface.hpp +++ b/xs/src/Surface.hpp @@ -23,6 +23,7 @@ class Surface unsigned short thickness_layers; // in layers double bridge_angle; unsigned short extra_perimeters; + bool in_collection; }; } diff --git a/xs/xsp/Surface.xsp b/xs/xsp/Surface.xsp index 173b3f260..067289ffe 100644 --- a/xs/xsp/Surface.xsp +++ b/xs/xsp/Surface.xsp @@ -6,8 +6,6 @@ %} %name{Slic3r::Surface} class Surface { - %name{_clone} Surface(Surface& self); - ~Surface(); ExPolygon* expolygon() %code{% const char* CLASS = "Slic3r::ExPolygon::XS"; RETVAL = new ExPolygon(THIS->expolygon); %}; double thickness() @@ -36,6 +34,14 @@ _new(CLASS, expolygon, surface_type, thickness, thickness_layers, bridge_angle, OUTPUT: RETVAL +void +Surface::DESTROY() + CODE: + if (!THIS->in_collection) { + delete THIS; + THIS = NULL; + } + SurfaceType Surface::surface_type(...) CODE: diff --git a/xs/xsp/SurfaceCollection.xsp b/xs/xsp/SurfaceCollection.xsp index ef18fff48..2cd9df3ae 100644 --- a/xs/xsp/SurfaceCollection.xsp +++ b/xs/xsp/SurfaceCollection.xsp @@ -19,6 +19,7 @@ SurfaceCollection::new(...) RETVAL->surfaces.resize(items-1); for (unsigned int i = 1; i < items; i++) { RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) )); + RETVAL->surfaces[i-1].in_collection = true; } OUTPUT: RETVAL @@ -31,7 +32,7 @@ SurfaceCollection::arrayref() int i = 0; for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) { SV* sv = newSV(0); - sv_setref_pv( sv, "Slic3r::Surface", new Surface(*it) ); + sv_setref_pv( sv, "Slic3r::Surface", &*it ); av_store(av, i++, sv); } RETVAL = newRV_noinc((SV*)av); @@ -43,6 +44,7 @@ SurfaceCollection::append(...) CODE: for (unsigned int i = 1; i < items; i++) { THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) ))); + THIS->surfaces.back().in_collection = true; } %}