fixes 0003771: Memory leak in Part.Face.Surface

This commit is contained in:
wmayer
2019-01-23 22:38:51 +01:00
parent 86d8372056
commit 2aee1e8368
5 changed files with 98 additions and 35 deletions

View File

@@ -695,6 +695,7 @@ Py::Object TopoShapeFacePy::getSurface() const
{
const TopoDS_Face& f = TopoDS::Face(getTopoShapePtr()->getShape());
BRepAdaptor_Surface adapt(f);
Base::PyObjectBase* surface = 0;
switch(adapt.GetType())
{
case GeomAbs_Plane:
@@ -703,7 +704,8 @@ Py::Object TopoShapeFacePy::getSurface() const
Handle(Geom_Plane) this_surf = Handle(Geom_Plane)::DownCast
(plane->handle());
this_surf->SetPln(adapt.Plane());
return Py::Object(new PlanePy(plane),true);
surface = new PlanePy(plane);
break;
}
case GeomAbs_Cylinder:
{
@@ -711,7 +713,8 @@ Py::Object TopoShapeFacePy::getSurface() const
Handle(Geom_CylindricalSurface) this_surf = Handle(Geom_CylindricalSurface)::DownCast
(cylinder->handle());
this_surf->SetCylinder(adapt.Cylinder());
return Py::Object(new CylinderPy(cylinder),true);
surface = new CylinderPy(cylinder);
break;
}
case GeomAbs_Cone:
{
@@ -719,7 +722,8 @@ Py::Object TopoShapeFacePy::getSurface() const
Handle(Geom_ConicalSurface) this_surf = Handle(Geom_ConicalSurface)::DownCast
(cone->handle());
this_surf->SetCone(adapt.Cone());
return Py::Object(new ConePy(cone),true);
surface = new ConePy(cone);
break;
}
case GeomAbs_Sphere:
{
@@ -727,7 +731,8 @@ Py::Object TopoShapeFacePy::getSurface() const
Handle(Geom_SphericalSurface) this_surf = Handle(Geom_SphericalSurface)::DownCast
(sphere->handle());
this_surf->SetSphere(adapt.Sphere());
return Py::Object(new SpherePy(sphere),true);
surface = new SpherePy(sphere);
break;
}
case GeomAbs_Torus:
{
@@ -735,17 +740,20 @@ Py::Object TopoShapeFacePy::getSurface() const
Handle(Geom_ToroidalSurface) this_surf = Handle(Geom_ToroidalSurface)::DownCast
(toroid->handle());
this_surf->SetTorus(adapt.Torus());
return Py::Object(new ToroidPy(toroid),true);
surface = new ToroidPy(toroid);
break;
}
case GeomAbs_BezierSurface:
{
GeomBezierSurface* surf = new GeomBezierSurface(adapt.Bezier());
return Py::Object(new BezierSurfacePy(surf),true);
surface = new BezierSurfacePy(surf);
break;
}
case GeomAbs_BSplineSurface:
{
GeomBSplineSurface* surf = new GeomBSplineSurface(adapt.BSpline());
return Py::Object(new BSplineSurfacePy(surf),true);
surface = new BSplineSurfacePy(surf);
break;
}
case GeomAbs_SurfaceOfRevolution:
{
@@ -757,7 +765,8 @@ Py::Object TopoShapeFacePy::getSurface() const
}
if (!rev.IsNull()) {
GeomSurfaceOfRevolution* surf = new GeomSurfaceOfRevolution(rev);
return Py::Object(new SurfaceOfRevolutionPy(surf),true);
surface = new SurfaceOfRevolutionPy(surf);
break;
}
else {
throw Py::RuntimeError("Failed to convert to surface of revolution");
@@ -773,7 +782,8 @@ Py::Object TopoShapeFacePy::getSurface() const
}
if (!ext.IsNull()) {
GeomSurfaceOfExtrusion* surf = new GeomSurfaceOfExtrusion(ext);
return Py::Object(new SurfaceOfExtrusionPy(surf),true);
surface = new SurfaceOfExtrusionPy(surf);
break;
}
else {
throw Py::RuntimeError("Failed to convert to surface of extrusion");
@@ -789,7 +799,8 @@ Py::Object TopoShapeFacePy::getSurface() const
}
if (!off.IsNull()) {
GeomOffsetSurface* surf = new GeomOffsetSurface(off);
return Py::Object(new OffsetSurfacePy(surf),true);
surface = new OffsetSurfacePy(surf);
break;
}
else {
throw Py::RuntimeError("Failed to convert to offset surface");
@@ -799,6 +810,11 @@ Py::Object TopoShapeFacePy::getSurface() const
break;
}
if (surface) {
surface->setNotTracking();
return Py::asObject(surface);
}
throw Py::TypeError("undefined surface type");
}