1
0
Fork 0

fix for segmentation fault on ocean tiles

- don't save the intermediate data file when tile is ocean only
- don't do anything in later stages if intermediate file isn't found
This commit is contained in:
2012-10-11 19:20:12 -04:00
parent 1abe94feba
commit 531ec93b29
3 changed files with 167 additions and 148 deletions

View file

@ -27,32 +27,15 @@
#include <iomanip>
//#include <boost/foreach.hpp>
//#include <simgear/compiler.h>
//#include <simgear/constants.h>
//#include <simgear/math/sg_geodesy.hxx>
//#include <simgear/math/SGGeometry.hxx>
//#include <simgear/misc/sg_dir.hxx>
//#include <simgear/misc/texcoord.hxx>
//#include <simgear/io/sg_binobj.hxx>
//#include <simgear/structure/exception.hxx>
#include <simgear/debug/logstream.hxx>
//#include <CGAL/Plane_3.h>
//#include <Geometry/poly_support.hxx>
//#include <Geometry/poly_extra.hxx>
#include "tgconstruct.hxx"
//#include "usgs.hxx"
//using std::string;
// Constructor
TGConstruct::TGConstruct():
ignoreLandmass(false),
debug_all(false),
ds_id((void*)-1)
ds_id((void*)-1),
isOcean(false)
{ }
@ -109,6 +92,7 @@ void TGConstruct::ConstructBucketStage1() {
if ( LoadLandclassPolys() == 0 ) {
// don't build the tile if there is no 2d data ... it *must*
// be ocean and the sim can build the tile on the fly.
SetOceanTile();
return;
}
@ -133,101 +117,105 @@ void TGConstruct::ConstructBucketStage1() {
}
void TGConstruct::ConstructBucketStage2() {
// First, set the precision of floating point logging:
SG_LOG(SG_GENERAL, SG_ALERT, std::setprecision(12) << std::fixed);
SG_LOG(SG_GENERAL, SG_ALERT, "\nConstructing tile ID " << bucket.gen_index_str() << " in " << bucket.gen_base_path() );
if ( !IsOceanTile() ) {
// First, set the precision of floating point logging:
SG_LOG(SG_GENERAL, SG_ALERT, std::setprecision(12) << std::fixed);
SG_LOG(SG_GENERAL, SG_ALERT, "\nConstructing tile ID " << bucket.gen_index_str() << " in " << bucket.gen_base_path() );
/* 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 );
} else {
strcpy( ds_name, "" );
/* 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 );
} else {
strcpy( ds_name, "" );
}
// STEP 7)
// Need the array of elevation data for stage 2
LoadElevationArray();
// STEP 6)
// Merge in Shared data - should just be x,y nodes on the borders from stage1
LoadSharedEdgeData( 1 );
// STEP 7)
// Fix T-Junctions by finding nodes that lie close to polygon edges, and
// inserting them into the edge
FixTJunctions();
// STEP 8)
// Generate triangles - we can't generate the node-face lookup table
// until all polys are tesselated, as extra nodes can still be generated
TesselatePolys();
// STEP 9)
// Generate triangle vertex coordinates to node index lists
// NOTE: After this point, no new nodes can be added
LookupNodesPerVertex();
// STEP 10)
// Interpolate elevations, and flatten stuff
CalcElevations();
// STEP 11)
// Generate face_connected list
LookupFacesPerNode();
// STEP 12)
// Save the tile boundary info for stage 3
// includes elevation info, and a list of connected triangles
SaveSharedEdgeData( 2 );
}
// STEP 7)
// Need the array of elevation data for stage 2
LoadElevationArray();
// STEP 6)
// Merge in Shared data - should just be x,y nodes on the borders from stage1
LoadSharedEdgeData( 1 );
// STEP 7)
// Fix T-Junctions by finding nodes that lie close to polygon edges, and
// inserting them into the edge
FixTJunctions();
// STEP 8)
// Generate triangles - we can't generate the node-face lookup table
// until all polys are tesselated, as extra nodes can still be generated
TesselatePolys();
// STEP 9)
// Generate triangle vertex coordinates to node index lists
// NOTE: After this point, no new nodes can be added
LookupNodesPerVertex();
// STEP 10)
// Interpolate elevations, and flatten stuff
CalcElevations();
// STEP 11)
// Generate face_connected list
LookupFacesPerNode();
// STEP 12)
// Save the tile boundary info for stage 3
// includes elevation info, and a list of connected triangles
SaveSharedEdgeData( 2 );
}
void TGConstruct::ConstructBucketStage3() {
// First, set the precision of floating point logging:
SG_LOG(SG_GENERAL, SG_ALERT, std::setprecision(12) << std::fixed);
SG_LOG(SG_GENERAL, SG_ALERT, "\nConstructing tile ID " << bucket.gen_index_str() << " in " << bucket.gen_base_path() );
if ( !IsOceanTile() ) {
// First, set the precision of floating point logging:
SG_LOG(SG_GENERAL, SG_ALERT, std::setprecision(12) << std::fixed);
SG_LOG(SG_GENERAL, SG_ALERT, "\nConstructing tile ID " << bucket.gen_index_str() << " in " << bucket.gen_base_path() );
/* 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 );
} else {
strcpy( ds_name, "" );
}
/* 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 );
} else {
strcpy( ds_name, "" );
}
// Load in the neighbor faces and elevation data
LoadSharedEdgeDataStage2();
// Load in the neighbor faces and elevation data
LoadSharedEdgeDataStage2();
// STEP 12)
// Average out the elevation for nodes on tile boundaries
AverageEdgeElevations();
// STEP 12)
// Average out the elevation for nodes on tile boundaries
AverageEdgeElevations();
// STEP 12)
// Calculate Face Normals
CalcFaceNormals();
// STEP 12)
// Calculate Face Normals
CalcFaceNormals();
// STEP 13)
// Calculate Point Normals
CalcPointNormals();
// STEP 13)
// Calculate Point Normals
CalcPointNormals();
#if 0
if ( c.get_cover().size() > 0 ) {
// Now for all the remaining "default" land cover polygons, assign
// each one it's proper type from the land use/land cover
// database.
fix_land_cover_assignments( c );
}
if ( c.get_cover().size() > 0 ) {
// Now for all the remaining "default" land cover polygons, assign
// each one it's proper type from the land use/land cover
// database.
fix_land_cover_assignments( c );
}
#endif
// STEP 14)
// Calculate Texture Coordinates
CalcTextureCoordinates();
// STEP 14)
// Calculate Texture Coordinates
CalcTextureCoordinates();
// STEP 16)
// Generate the btg file
WriteBtgFile();
// STEP 16)
// Generate the btg file
WriteBtgFile();
// STEP 17)
// Write Custom objects to .stg file
AddCustomObjects();
// STEP 17)
// Write Custom objects to .stg file
AddCustomObjects();
}
}

View file

@ -123,10 +123,17 @@ private:
// All Nodes
TGNodes nodes;
// ocean tile?
bool isOcean;
// Neighbor Faces
neighbor_face_list neighbor_faces;
private:
// Ocean tile or not
void SetOceanTile() { isOcean = true; }
bool IsOceanTile() { return isOcean; }
// Load Data
void LoadElevationArray( void );
int LoadLandclassPolys( void );

View file

@ -354,58 +354,63 @@ void TGConstruct::SaveToIntermediateFiles( int stage )
switch( stage ) {
case 1: // Save the clipped polys and node list
{
dir = share_base + "/stage1/" + bucket.gen_base_path();
/* Only create the file this isn't an ocean tile */
if ( !IsOceanTile() ) {
dir = share_base + "/stage1/" + bucket.gen_base_path();
SGPath sgp( dir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
SGPath sgp( dir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ofstream ofs_cp( file.c_str() );
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ofstream ofs_cp( file.c_str() );
// first, set the precision
ofs_cp << std::setprecision(15);
ofs_cp << std::fixed;
ofs_cp << polys_clipped;
ofs_cp.close();
// first, set the precision
ofs_cp << std::setprecision(15);
ofs_cp << std::fixed;
ofs_cp << polys_clipped;
ofs_cp.close();
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ofstream ofs_n( file.c_str() );
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ofstream ofs_n( file.c_str() );
// first, set the precision
ofs_n << std::setprecision(15);
ofs_n << std::fixed;
ofs_n << nodes;
ofs_n.close();
}
// first, set the precision
ofs_n << std::setprecision(15);
ofs_n << std::fixed;
ofs_n << nodes;
ofs_n.close();
break;
}
case 2: // Save the clipped polys and node list
{
dir = share_base + "/stage2/" + bucket.gen_base_path();
if ( !IsOceanTile() ) {
dir = share_base + "/stage2/" + bucket.gen_base_path();
SGPath sgp( dir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
SGPath sgp( dir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ofstream ofs_cp( file.c_str() );
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ofstream ofs_cp( file.c_str() );
// first, set the precision
ofs_cp << std::setprecision(15);
ofs_cp << std::fixed;
ofs_cp << polys_clipped;
ofs_cp.close();
// first, set the precision
ofs_cp << std::setprecision(15);
ofs_cp << std::fixed;
ofs_cp << polys_clipped;
ofs_cp.close();
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ofstream ofs_n( file.c_str() );
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ofstream ofs_n( file.c_str() );
// first, set the precision
ofs_n << std::setprecision(15);
ofs_n << std::fixed;
ofs_n << nodes;
ofs_n.close();
// first, set the precision
ofs_n << std::setprecision(15);
ofs_n << std::fixed;
ofs_n << nodes;
ofs_n.close();
}
break;
}
}
@ -512,6 +517,7 @@ void TGConstruct::LoadFromIntermediateFiles( int stage )
{
string dir;
string file;
bool read_ok = false;
switch( stage ) {
case 1: // Load the clipped polys and node list
@ -520,14 +526,21 @@ void TGConstruct::LoadFromIntermediateFiles( int stage )
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ifstream ifs_cp( file.c_str() );
ifs_cp >> polys_clipped;
ifs_cp.close();
if ( ifs_cp.good() ) {
ifs_cp >> polys_clipped;
ifs_cp.close();
file = dir + "/" + bucket.gen_index_str() + "_nodes";
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ifstream ifs_n( file.c_str() );
if ( ifs_n.good() ) {
ifs_n >> nodes;
ifs_n.close();
read_ok = true;
}
}
std::ifstream ifs_n( file.c_str() );
ifs_n >> nodes;
ifs_n.close();
break;
}
@ -537,15 +550,26 @@ void TGConstruct::LoadFromIntermediateFiles( int stage )
file = dir + "/" + bucket.gen_index_str() + "_clipped_polys";
std::ifstream ifs_cp( file.c_str() );
ifs_cp >> polys_clipped;
ifs_cp.close();
if ( ifs_cp.good() ) {
ifs_cp >> polys_clipped;
ifs_cp.close();
file = dir + "/" + bucket.gen_index_str() + "_nodes";
file = dir + "/" + bucket.gen_index_str() + "_nodes";
std::ifstream ifs_n( file.c_str() );
if ( ifs_n.good() ) {
ifs_n >> nodes;
ifs_n.close();
read_ok = true;
}
}
std::ifstream ifs_n( file.c_str() );
ifs_n >> nodes;
ifs_n.close();
break;
}
}
if ( !read_ok ) {
SetOceanTile();
}
}