fix some uninitialized data found with valgrind
remove the cpu limit - tgconstruct should be able to run for weeks, now.
This commit is contained in:
parent
f24699ca05
commit
e6d8d69c87
2 changed files with 86 additions and 52 deletions
|
@ -73,6 +73,7 @@ TGConstruct::TGConstruct():
|
|||
useUKGrid(false),
|
||||
writeSharedEdges(true),
|
||||
useOwnSharedEdges(false),
|
||||
ignoreLandmass(false),
|
||||
debug_all(false),
|
||||
ds_id((void*)-1)
|
||||
{ }
|
||||
|
@ -558,16 +559,17 @@ int TGConstruct::LoadLandclassPolys( void ) {
|
|||
// load 2D polygons from all directories provided
|
||||
for ( i = 0; i < (int)load_dirs.size(); ++i ) {
|
||||
poly_path = get_work_base() + "/" + load_dirs[i] + '/' + base;
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "poly_path = " << poly_path);
|
||||
|
||||
string tile_str = bucket.gen_index_str();
|
||||
simgear::Dir d(poly_path);
|
||||
if (!d.exists()) {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "directory not found: " << poly_path);
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "directory not found: " << poly_path);
|
||||
continue;
|
||||
}
|
||||
|
||||
simgear::PathList files = d.children(simgear::Dir::TYPE_FILE);
|
||||
SG_LOG( SG_CLIPPER, SG_ALERT, files.size() << " Polys in " << d.path() );
|
||||
SG_LOG( SG_CLIPPER, SG_INFO, "Loading " << files.size() << " polys from " << d.path() );
|
||||
|
||||
BOOST_FOREACH(const SGPath& p, files) {
|
||||
if (p.file_base() != tile_str) {
|
||||
|
@ -580,17 +582,18 @@ int TGConstruct::LoadLandclassPolys( void ) {
|
|||
{
|
||||
// skipped!
|
||||
} else if (lext == "osgb36") {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, " Loading osgb36 poly definition file " << p.file());
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Loading osgb36 poly definition file");
|
||||
load_osgb36_poly( p.str() );
|
||||
++count;
|
||||
} else {
|
||||
load_poly( p.str() );
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, " Loaded " << p.file());
|
||||
++count;
|
||||
}
|
||||
} // of directory file children
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, " loaded " << count << " total polys");
|
||||
}
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, " Total polys used for this tile: " << count );
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -601,7 +604,11 @@ int TGConstruct::LoadLandclassPolys( void ) {
|
|||
// to reduce the number of separate polygons.
|
||||
void TGConstruct::add_to_polys ( TGPolygon &accum, const TGPolygon &poly) {
|
||||
if ( accum.contours() > 0 ) {
|
||||
#if USE_CLIPPER
|
||||
accum = tgPolygonUnionClipper( accum, poly );
|
||||
#else
|
||||
accum = tgPolygonUnion( accum, poly );
|
||||
#endif
|
||||
} else {
|
||||
accum = poly;
|
||||
}
|
||||
|
@ -1235,7 +1242,11 @@ void TGConstruct::merge_slivers( TGLandclass& clipped, poly_list& slivers_list
|
|||
|
||||
poly = clipped.get_poly( area, shape, segment );
|
||||
original_contours = poly.contours();
|
||||
#if USE_CLIPPER
|
||||
result = tgPolygonUnionClipper( poly, sliver );
|
||||
#else
|
||||
result = tgPolygonUnion( poly, sliver );
|
||||
#endif
|
||||
result_contours = result.contours();
|
||||
|
||||
if ( original_contours == result_contours ) {
|
||||
|
@ -1246,7 +1257,11 @@ void TGConstruct::merge_slivers( TGLandclass& clipped, poly_list& slivers_list
|
|||
|
||||
/* add the sliver to the clip_mask, too */
|
||||
TGPolygon mask = clipped.get_mask( area, shape );
|
||||
#if USE_CLIPPER
|
||||
result = tgPolygonUnionClipper( mask, sliver );
|
||||
#else
|
||||
result = tgPolygonUnion( mask, sliver );
|
||||
#endif
|
||||
clipped.set_mask( area, shape, result );
|
||||
|
||||
if ( IsDebugShape( shape_id ) ) {
|
||||
|
@ -1287,7 +1302,11 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
|
||||
#if USE_ACCUMULATOR
|
||||
|
||||
#if USE_CLIPPER
|
||||
tgPolygonInitClipperAccumulator();
|
||||
#else
|
||||
tgPolygonInitGPCAccumulator();
|
||||
#endif
|
||||
|
||||
#else
|
||||
accum.erase();
|
||||
|
@ -1325,17 +1344,29 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
for ( i = 0; i < TG_MAX_AREA_TYPES; i++ ) {
|
||||
if ( is_landmass_area( i ) && !ignoreLandmass ) {
|
||||
for ( unsigned int j = 0; j < polys_in.area_size(i); ++j ) {
|
||||
#if USE_CLIPPER
|
||||
land_mask = tgPolygonUnionClipper( land_mask, polys_in.get_mask(i, j) );
|
||||
#else
|
||||
land_mask = tgPolygonUnion( land_mask, polys_in.get_mask(i, j) );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
} else if ( is_water_area( i ) ) {
|
||||
for (unsigned int j = 0; j < polys_in.area_size(i); j++) {
|
||||
#if USE_CLIPPER
|
||||
water_mask = tgPolygonUnionClipper( water_mask, polys_in.get_mask(i, j) );
|
||||
#else
|
||||
water_mask = tgPolygonUnion( water_mask, polys_in.get_mask(i, j) );
|
||||
#endif
|
||||
}
|
||||
} else if ( is_island_area( i ) ) {
|
||||
for (unsigned int j = 0; j < polys_in.area_size(i); j++) {
|
||||
#if USE_CLIPPER
|
||||
island_mask = tgPolygonUnionClipper( island_mask, polys_in.get_mask(i, j) );
|
||||
#else
|
||||
island_mask = tgPolygonUnion( island_mask, polys_in.get_mask(i, j) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1358,13 +1389,21 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
|
||||
// if not a hole, clip the area to the land_mask
|
||||
if ( !ignoreLandmass && !is_hole_area( i ) ) {
|
||||
#if USE_CLIPPER
|
||||
tmp = tgPolygonIntClipper( tmp, land_mask );
|
||||
#else
|
||||
tmp = tgPolygonInt( tmp, land_mask );
|
||||
#endif
|
||||
}
|
||||
|
||||
// if a water area, cut out potential islands
|
||||
if ( is_water_area( i ) ) {
|
||||
// clip against island mask
|
||||
#if USE_CLIPPER
|
||||
tmp = tgPolygonDiffClipper( tmp, island_mask );
|
||||
#else
|
||||
tmp = tgPolygonDiff( tmp, island_mask );
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( IsDebugShape( polys_in.get_shape( i, j ).id ) ) {
|
||||
|
@ -1373,12 +1412,23 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
WriteDebugPoly( "pre-clip", name, tmp );
|
||||
}
|
||||
|
||||
#if USE_CLIPPER
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
clipped = tgPolygonDiffClipperWithAccumulator( tmp );
|
||||
#else
|
||||
clipped = tgPolygonDiffClipper( tmp, accum );
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
clipped = tgPolygonDiffWithAccumulator( tmp );
|
||||
#else
|
||||
clipped = tgPolygonDiff( tmp, accum );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// only add to output list if the clip left us with a polygon
|
||||
if ( clipped.contours() > 0 ) {
|
||||
|
@ -1410,12 +1460,23 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
}
|
||||
}
|
||||
|
||||
#if USE_CLIPPER
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
tgPolygonAddToClipperAccumulator( tmp );
|
||||
#else
|
||||
accum = tgPolygonUnionClipper( tmp, accum );
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
tgPolygonAddToAccumulator( tmp );
|
||||
#else
|
||||
accum = tgPolygonUnion( tmp, accum );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1432,10 +1493,22 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
slivers.clear();
|
||||
|
||||
// finally, what ever is left over goes to ocean
|
||||
#if USE_CLIPPER
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
remains = tgPolygonDiffClipperWithAccumulator( safety_base );
|
||||
#else
|
||||
remains = tgPolygonDiffClipper( safety_base, accum );
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if USE_ACCUMULATOR
|
||||
remains = tgPolygonDiffWithAccumulator( safety_base );
|
||||
#else
|
||||
remains = tgPolygonDiff( safety_base, accum );
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if ( remains.contours() > 0 ) {
|
||||
|
@ -1472,7 +1545,6 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
sp.set_material( material );
|
||||
sp.set_poly( remains );
|
||||
shape.SetMask( remains );
|
||||
shape.textured = false;
|
||||
shape.sps.push_back( sp );
|
||||
|
||||
polys_clipped.add_shape( (int)get_sliver_target_area_type(), shape );
|
||||
|
@ -1481,7 +1553,11 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
|||
|
||||
#if USE_ACCUMULATOR
|
||||
|
||||
#if USE_CLIPPER
|
||||
tgPolygonFreeClipperAccumulator();
|
||||
#else
|
||||
tgPolygonFreeGPCAccumulator();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1934,6 +2010,7 @@ void TGConstruct::WriteBtgFile( void )
|
|||
}
|
||||
|
||||
void TGConstruct::CleanClippedPolys() {
|
||||
unsigned int before, after;
|
||||
|
||||
// Clean the polys
|
||||
for ( unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++ ) {
|
||||
|
@ -2024,7 +2101,9 @@ void TGConstruct::ConstructBucketStage1() {
|
|||
/* If we have some debug IDs, create a datasource */
|
||||
if ( debug_shapes.size() || debug_all ) {
|
||||
sprintf(ds_name, "%s/constructdbg_%s", debug_path.c_str(), bucket.gen_index_str().c_str() );
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Debug_string: " << ds_name );
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Construct tile, bucket = " << bucket << " debug_string: " << ds_name );
|
||||
} else {
|
||||
strcpy( ds_name, "" );
|
||||
}
|
||||
|
||||
// STEP 1)
|
||||
|
|
|
@ -29,14 +29,6 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h> // set mem allocation limit
|
||||
#endif
|
||||
#ifndef _MSC_VER
|
||||
# include <sys/resource.h> // set mem allocation limit
|
||||
# include <unistd.h> // set mem allocation limit
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <iostream>
|
||||
|
@ -269,43 +261,6 @@ int main(int argc, char **argv) {
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( _MSC_VER )
|
||||
// the next bit crashes Cygwin for me - DCL
|
||||
// MSVC does not have the function or variable type defined - BRF
|
||||
#else
|
||||
// set mem allocation limit. Reason: occasionally the triangle()
|
||||
// routine can blow up and allocate memory forever. We'd like
|
||||
// this process to die before things get out of hand so we can try
|
||||
// again with a smaller interior angle limit.
|
||||
struct rlimit limit;
|
||||
limit.rlim_cur = 40000000;
|
||||
limit.rlim_max = 40000000;
|
||||
|
||||
#if 0
|
||||
result = setrlimit( RLIMIT_DATA, &limit );
|
||||
cout << "result of setting mem limit = " << result << endl;
|
||||
result = setrlimit( RLIMIT_STACK, &limit );
|
||||
cout << "result of setting mem limit = " << result << endl;
|
||||
result = setrlimit( RLIMIT_CORE, &limit );
|
||||
cout << "result of setting mem limit = " << result << endl;
|
||||
result = setrlimit( RLIMIT_RSS, &limit );
|
||||
cout << "result of setting mem limit = " << result << endl;
|
||||
#endif
|
||||
|
||||
// cpu time limit since occassionally the triangulator can go into
|
||||
// an infinite loop.
|
||||
limit.rlim_cur = 43200; // seconds
|
||||
limit.rlim_max = 43200; // seconds
|
||||
if (setrlimit( RLIMIT_CPU, &limit )) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Error setting RLIMIT_CPU, aborting");
|
||||
exit(-1);
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Setting RLIMIT_CPU to " << limit.rlim_cur << " seconds");
|
||||
};
|
||||
|
||||
#endif // end of stuff that crashes Cygwin
|
||||
|
||||
// main construction data management class
|
||||
TGConstruct* c;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue