fix mem-leaks, autoptr geometry

This commit is contained in:
Joachim Schoeberl 2013-02-26 13:00:06 +00:00
parent 7aa0128d6f
commit 22d054bc89
6 changed files with 51 additions and 99 deletions

View File

@ -17,7 +17,8 @@ extern "C" int Ng_CSG_Init (Tcl_Interp * interp);
namespace netgen
{
extern DLL_HEADER NetgenGeometry * ng_geometry;
// extern DLL_HEADER NetgenGeometry * ng_geometry;
extern DLL_HEADER AutoPtr<NetgenGeometry> ng_geometry;
extern DLL_HEADER AutoPtr<Mesh> mesh;
static VisualSceneGeometry vsgeom;
@ -33,7 +34,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * csgeom = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * csgeom = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (csgeom)
{
double detail = atof (Tcl_GetVar (interp, "::geooptions.detail", 0));
@ -52,7 +53,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
const char * command = argv[1];
@ -107,7 +108,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -142,7 +143,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -180,7 +181,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -207,7 +208,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -245,7 +246,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -272,7 +273,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -305,7 +306,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -336,7 +337,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -367,7 +368,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -492,7 +493,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -521,7 +522,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (!geometry)
{
Tcl_SetResult (interp, err_needscsgeometry, TCL_STATIC);
@ -610,7 +611,7 @@ namespace netgen
VisualScene * CSGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (geometry)
{
vsgeom.SetGeometry (geometry);

View File

@ -17,7 +17,7 @@ namespace netgen
for ( int i = 0; i < bcnames.Size(); i++ )
delete bcnames[i];
for (int i=0; i<materials.Size(); i++)
delete materials[i];
delete [] materials[i];
}

View File

@ -109,7 +109,8 @@ namespace netgen
// global variable mesh (should not be used in libraries)
AutoPtr<Mesh> mesh;
NetgenGeometry * ng_geometry = NULL; // new NetgenGeometry;
// NetgenGeometry * ng_geometry = NULL; // new NetgenGeometry;
AutoPtr<NetgenGeometry> ng_geometry;
// extern NetgenGeometry * ng_geometry;
// extern AutoPtr<Mesh> mesh;
@ -145,9 +146,12 @@ void Ng_LoadGeometry (const char * filename)
NetgenGeometry * hgeom = geometryregister[i]->Load (filename);
if (hgeom)
{
/*
delete ng_geometry;
ng_geometry = hgeom;
*/
ng_geometry.Reset (hgeom);
mesh.Reset();
return;
}
@ -157,8 +161,11 @@ void Ng_LoadGeometry (const char * filename)
// can be used to reset geometry
if (strcmp(filename,"")==0)
{
/*
delete ng_geometry;
ng_geometry = new NetgenGeometry();
*/
ng_geometry.Reset (new NetgenGeometry());
return;
}
@ -177,55 +184,14 @@ void Ng_LoadMeshFromStream ( istream & input )
NetgenGeometry * hgeom = geometryregister[i]->LoadFromMeshFile (input);
if (hgeom)
{
/*
delete ng_geometry;
ng_geometry = hgeom;
*/
ng_geometry.Reset (hgeom);
break;
}
}
#ifdef LOADOLD
if(input.good())
{
string auxstring;
input >> auxstring;
if(auxstring == "csgsurfaces")
{
/*
if (geometry)
{
geometry.Reset (new CSGeometry (""));
}
if (stlgeometry)
{
delete stlgeometry;
stlgeometry = NULL;
}
#ifdef OCCGEOMETRY
if (occgeometry)
{
delete occgeometry;
occgeometry = NULL;
}
#endif
#ifdef ACIS
if (acisgeometry)
{
delete acisgeometry;
acisgeometry = NULL;
}
#endif
geometry2d.Reset (0);
*/
// geometry -> LoadSurfaces(input);
CSGeometry * geometry = new CSGeometry ("");
geometry -> LoadSurfaces(input);
delete ng_geometry;
ng_geometry = geometry;
}
}
#endif
}
@ -236,9 +202,11 @@ void Ng_LoadMesh (const char * filename)
#ifdef PARALLEL
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
#endif
if (id == 0)
{
#endif
if ( (strlen (filename) > 4) &&
strcmp (filename + (strlen (filename)-4), ".vol") != 0 )
{
@ -318,9 +286,7 @@ void Ng_LoadMesh (const char * filename)
mesh -> Distribute(volume_weights, surface_weights, segment_weights);
}
}
#endif
}
#ifdef PARALLEL
else
{
mesh.Reset (new Mesh());
@ -688,7 +654,7 @@ void Ng_GetNormalVector (int sei, int locpi, double * nv)
nv[2] = n(2);
}
#endif
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (geometry)
{
n = geometry->GetSurface (surfi) -> GetNormalVector(p);
@ -2175,7 +2141,7 @@ int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss, int
#endif
{
// ref = new RefinementSurfaces(*geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry);
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.Ptr());
if (geometry)
{
opt = new MeshOptimize2dSurfaces(*geometry);

View File

@ -31,5 +31,7 @@ libmesh_la_SOURCES = adfront2.cpp adfront3.cpp bisect.cpp boundarylayer.cpp \
parallelmesh.cpp paralleltop.cpp paralleltop.hpp basegeom.cpp
libmesh_la_LIBADD = $(top_builddir)/libsrc/linalg/libla.la \
$(top_builddir)/libsrc/gprim/libgprim.la \
$(top_builddir)/libsrc/general/libgen.la
$(top_builddir)/libsrc/gprim/libgprim.la \
$(top_builddir)/libsrc/general/libgen.la \
-lz

View File

@ -211,17 +211,15 @@ namespace netgen
RecPol (int amaxorder)
{
maxorder = amaxorder;
// cout << "maxo = " << maxorder << endl;
a = new double[maxorder+1];
b = new double[maxorder+1];
c = new double[maxorder+1];
}
~RecPol ()
{
delete a;
delete b;
delete c;
delete [] a;
delete [] b;
delete [] c;
}
template <class S, class T>

View File

@ -361,6 +361,7 @@ namespace netgen
{
ofstream outfile(filename.c_str());
// ogzstream outfile( (filename+".gz") .c_str());
Save(outfile);
}
@ -408,54 +409,38 @@ namespace netgen
{
if ((*this)[sei].GetIndex())
{
outfile.width(8);
outfile << GetFaceDescriptor((*this)[sei].GetIndex ()).SurfNr()+1;
outfile.width(8);
outfile << GetFaceDescriptor((*this)[sei].GetIndex ()).BCProperty();
outfile.width(8);
outfile << GetFaceDescriptor((*this)[sei].GetIndex ()).DomainIn();
outfile.width(8);
outfile << GetFaceDescriptor((*this)[sei].GetIndex ()).DomainOut();
outfile << " " << GetFaceDescriptor((*this)[sei].GetIndex ()).SurfNr()+1;
outfile << " " << GetFaceDescriptor((*this)[sei].GetIndex ()).BCProperty();
outfile << " " << GetFaceDescriptor((*this)[sei].GetIndex ()).DomainIn();
outfile << " " << GetFaceDescriptor((*this)[sei].GetIndex ()).DomainOut();
}
else
outfile << " 0 0 0";
outfile << " 0 0 0";
Element2d sel = (*this)[sei];
if (invertsurf)
sel.Invert();
outfile.width(8);
outfile << sel.GetNP();
outfile << " " << sel.GetNP();
for (j = 0; j < sel.GetNP(); j++)
{
outfile.width(8);
outfile << sel[j];
}
outfile << " " << sel[j];
switch (geomtype)
{
case GEOM_STL:
for (j = 1; j <= sel.GetNP(); j++)
{
outfile.width(7);
outfile << " " << sel.GeomInfoPi(j).trignum;
}
outfile << " " << sel.GeomInfoPi(j).trignum;
break;
case GEOM_OCC: case GEOM_ACIS:
for (j = 1; j <= sel.GetNP(); j++)
{
outfile.width(7);
outfile << " " << sel.GeomInfoPi(j).u;
outfile << " " << sel.GeomInfoPi(j).v;
}
break;
default:
; // outfile << "\n";
;
}
outfile << "\n";
}