1
0
Fork 0

fix memory leak in tgconstruct

This commit is contained in:
Peter Sadrozinski 2013-09-08 14:04:17 -04:00
parent d13ec65114
commit ecb1653eee
4 changed files with 10 additions and 10 deletions

View file

@ -49,10 +49,6 @@ TGConstruct::TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLock
// Destructor // Destructor
TGConstruct::~TGConstruct() { TGConstruct::~TGConstruct() {
// land class polygons
polys_in.clear();
polys_clipped.clear();
// All Nodes // All Nodes
nodes.clear(); nodes.clear();
} }

View file

@ -34,7 +34,7 @@
#include <simgear/threads/SGQueue.hxx> #include <simgear/threads/SGQueue.hxx>
#include <Array/array.hxx> #include <Array/array.hxx>
#include <terragear//tg_nodes.hxx> #include <terragear/tg_nodes.hxx>
#include <landcover/landcover.hxx> #include <landcover/landcover.hxx>
#include "tglandclass.hxx" #include "tglandclass.hxx"

View file

@ -45,8 +45,7 @@ int TGConstruct::LoadLandclassPolys( void ) {
string base = bucket.gen_base_path(); string base = bucket.gen_base_path();
string poly_path; string poly_path;
int total_polys_read = 0; int total_polys_read = 0;
tgPolygon poly;
polys_in.clear();
// load 2D polygons from all directories provided // load 2D polygons from all directories provided
for ( i = 0; i < (int)load_dirs.size(); ++i ) { for ( i = 0; i < (int)load_dirs.size(); ++i ) {
@ -82,7 +81,6 @@ int TGConstruct::LoadLandclassPolys( void ) {
SG_LOG( SG_GENERAL, SG_DEBUG, " Load " << count << " polys from " << p.realpath() ); SG_LOG( SG_GENERAL, SG_DEBUG, " Load " << count << " polys from " << p.realpath() );
for ( unsigned int i=0; i<count; i++ ) { for ( unsigned int i=0; i<count; i++ ) {
tgPolygon poly;
poly.LoadFromGzFile( fp ); poly.LoadFromGzFile( fp );
area = area_defs.get_area_priority( poly.GetFlag() ); area = area_defs.get_area_priority( poly.GetFlag() );
material = area_defs.get_area_name( area ); material = area_defs.get_area_name( area );

View file

@ -45,8 +45,11 @@ class TGLandclass
{ {
public: public:
TGLandclass() {}; TGLandclass() {};
~TGLandclass() {};
void init( unsigned int num_areas) { void init( unsigned int num_areas) {
clear();
for (unsigned int i=0; i<num_areas; i++) { for (unsigned int i=0; i<num_areas; i++) {
tgpolygon_list lc; tgpolygon_list lc;
lc.clear(); lc.clear();
@ -65,18 +68,21 @@ public:
{ {
return polys[area][poly]; return polys[area][poly];
} }
inline tgPolygon & get_poly( unsigned int area, unsigned int poly ) inline tgPolygon& get_poly( unsigned int area, unsigned int poly )
{ {
return polys[area][poly]; return polys[area][poly];
} }
inline void add_poly( unsigned int area, const tgPolygon& p ) inline void add_poly( unsigned int area, const tgPolygon& p )
{ {
if ( area > polys.capacity() ) { if ( area > polys.capacity() ) {
SG_LOG( SG_CLIPPER, SG_ALERT, " area out of bounds " << area << " of " << polys.capacity() ); SG_LOG( SG_GENERAL, SG_ALERT, " area out of bounds " << area << " of " << polys.capacity() );
exit(0); exit(0);
} }
polys[area].push_back( p ); polys[area].push_back( p );
} }
// TODO : Let's get rid of this - it was a memory leak, and the polygons should really be modified in place
// NOTE - this will be considerable work, so leaving as is for now (but fix the leak)
inline void set_poly( unsigned int area, unsigned int poly, const tgPolygon& p ) inline void set_poly( unsigned int area, unsigned int poly, const tgPolygon& p )
{ {
polys[area][poly] = p; polys[area][poly] = p;