Report errors on TileDetails callback failures
This callback can do out of memory and other failures, so catch those and report them.
This commit is contained in:
parent
2478bee97f
commit
1d59135652
@ -36,6 +36,7 @@
|
|||||||
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
||||||
#include <simgear/scene/util/OptionsReadFileCallback.hxx>
|
#include <simgear/scene/util/OptionsReadFileCallback.hxx>
|
||||||
#include <simgear/scene/util/SGNodeMasks.hxx>
|
#include <simgear/scene/util/SGNodeMasks.hxx>
|
||||||
|
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||||
|
|
||||||
#include "SGNodeTriangles.hxx"
|
#include "SGNodeTriangles.hxx"
|
||||||
#include "GroundLightManager.hxx"
|
#include "GroundLightManager.hxx"
|
||||||
@ -53,6 +54,8 @@ typedef std::list<SGDirectionalLightBin> SGDirectionalLightListBin;
|
|||||||
|
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
|
|
||||||
|
using ReadResult = osgDB::ReaderWriter::ReadResult;
|
||||||
|
|
||||||
// QuadTreeBuilder is used by Random Objects Generator
|
// QuadTreeBuilder is used by Random Objects Generator
|
||||||
typedef std::pair<osg::Node*, int> ModelLOD;
|
typedef std::pair<osg::Node*, int> ModelLOD;
|
||||||
struct MakeQuadLeaf {
|
struct MakeQuadLeaf {
|
||||||
@ -92,42 +95,55 @@ public:
|
|||||||
SG_LOG( SG_TERRAIN, SG_DEBUG, "SGTileDetailsCallback::~SGTileDetailsCallback() num cbs left " << num_tdcb );
|
SG_LOG( SG_TERRAIN, SG_DEBUG, "SGTileDetailsCallback::~SGTileDetailsCallback() num cbs left " << num_tdcb );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual osgDB::ReaderWriter::ReadResult readNode(
|
ReadResult readNode(const std::string&, const osgDB::Options*) override
|
||||||
const std::string&, const osgDB::Options*)
|
|
||||||
{
|
{
|
||||||
SGMaterialLibPtr matlib;
|
osg::ref_ptr<osg::Group> group;
|
||||||
osg::ref_ptr<SGMaterialCache> matcache;
|
simgear::ErrorReportContext ec{"btg", _path};
|
||||||
|
|
||||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
try {
|
||||||
group->setDataVariance(osg::Object::STATIC);
|
group = new osg::Group;
|
||||||
|
SGMaterialLibPtr matlib;
|
||||||
|
osg::ref_ptr<SGMaterialCache> matcache;
|
||||||
|
|
||||||
// generate textured triangle list
|
group->setDataVariance(osg::Object::STATIC);
|
||||||
std::vector<SGTriangleInfo> matTris;
|
|
||||||
GetNodeTriangles nodeTris(_gbs_center, &matTris);
|
|
||||||
_rootNode->accept( nodeTris );
|
|
||||||
|
|
||||||
// build matcache
|
// generate textured triangle list
|
||||||
matlib = _options->getMaterialLib();
|
std::vector<SGTriangleInfo> matTris;
|
||||||
if (matlib) {
|
GetNodeTriangles nodeTris(_gbs_center, &matTris);
|
||||||
SGGeod geodPos = SGGeod::fromCart(_gbs_center);
|
_rootNode->accept( nodeTris );
|
||||||
matcache = matlib->generateMatCache(geodPos, _options);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
// build matcache
|
||||||
// TEST : See if we can regenerate landclass shapes from node
|
matlib = _options->getMaterialLib();
|
||||||
for ( unsigned int i=0; i<matTris.size(); i++ ) {
|
if (matlib) {
|
||||||
matTris[i].dumpBorder(_gbs_center);
|
SGGeod geodPos = SGGeod::fromCart(_gbs_center);
|
||||||
}
|
matcache = matlib->generateMatCache(geodPos, _options);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
osg::LOD* lightLOD = generateLightingTileObjects(matTris, matcache);
|
#if 0
|
||||||
if (lightLOD) {
|
// TEST : See if we can regenerate landclass shapes from node
|
||||||
group->addChild(lightLOD);
|
for ( unsigned int i=0; i<matTris.size(); i++ ) {
|
||||||
}
|
matTris[i].dumpBorder(_gbs_center);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
osg::LOD* objectLOD = generateRandomTileObjects(matTris, matcache);
|
osg::LOD* lightLOD = generateLightingTileObjects(matTris, matcache);
|
||||||
if (objectLOD) {
|
if (lightLOD) {
|
||||||
group->addChild(objectLOD);
|
group->addChild(lightLOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
osg::LOD* objectLOD = generateRandomTileObjects(matTris, matcache);
|
||||||
|
if (objectLOD) {
|
||||||
|
group->addChild(objectLOD);
|
||||||
|
}
|
||||||
|
} catch (sg_exception& sge) {
|
||||||
|
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::BTGLoad,
|
||||||
|
"Failed to load BTG file:" + sge.getFormattedMessage(),
|
||||||
|
sge.getLocation());
|
||||||
|
return ReadResult::ERROR_IN_READING_FILE;
|
||||||
|
} catch (std::bad_alloc &e) {
|
||||||
|
simgear::reportFailure(simgear::LoadFailure::OutOfMemory, simgear::ErrorCode::BTGLoad,
|
||||||
|
"Out of memory loading tile details", sg_location{_path});
|
||||||
|
return ReadResult::INSUFFICIENT_MEMORY_TO_LOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
return group.release();
|
return group.release();
|
||||||
|
Loading…
Reference in New Issue
Block a user