Allow delayed setup of ErrorContext data

Permit no model data to be provided, when loading a model via the
modelLib API (d’oh)
This commit is contained in:
James Turner 2021-02-25 12:24:43 +00:00 committed by Automatic Release Builder
parent 81a489d81d
commit 651460bbc8
3 changed files with 24 additions and 8 deletions

View File

@ -87,6 +87,11 @@ ErrorReportContext::ErrorReportContext(const std::string& key, const std::string
} }
ErrorReportContext::ErrorReportContext(const ContextMap& context) ErrorReportContext::ErrorReportContext(const ContextMap& context)
{
addFromMap(context);
}
void ErrorReportContext::addFromMap(const ContextMap& context)
{ {
if (static_contextCallback) { if (static_contextCallback) {
for (const auto& p : context) { for (const auto& p : context) {
@ -96,6 +101,7 @@ ErrorReportContext::ErrorReportContext(const ContextMap& context)
} }
} }
ErrorReportContext::~ErrorReportContext() ErrorReportContext::~ErrorReportContext()
{ {
if (static_contextCallback) { if (static_contextCallback) {

View File

@ -78,7 +78,12 @@ public:
/** /**
Allow establishing multiple context values in a single operation Allow establishing multiple context values in a single operation
*/ */
ErrorReportContext(const ContextMap& context); ErrorReportContext(const ContextMap& context = {});
/**
@brief allowed delayed add of values
*/
void addFromMap(const ContextMap& context);
~ErrorReportContext(); ~ErrorReportContext();

View File

@ -143,7 +143,10 @@ SGModelLib::loadModel(const string &path,
// establish the error report context so we can attribute any load // establish the error report context so we can attribute any load
// errors correctly // errors correctly
simgear::ErrorReportContext ec(data->getErrorContext()); simgear::ErrorReportContext ec;
if (data) {
ec.addFromMap(data->getErrorContext());
}
if (load2DPanels) { if (load2DPanels) {
opt->setLoadPanel(static_panelFunc); opt->setLoadPanel(static_panelFunc);
@ -164,9 +167,10 @@ SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root,
proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER); proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER);
proxyNode->setFileName(0, path); proxyNode->setFileName(0, path);
// establish the error report context so we can attribute any load simgear::ErrorReportContext ec;
// errors correctly if (data) {
simgear::ErrorReportContext ec(data->getErrorContext()); ec.addFromMap(data->getErrorContext());
}
osg::ref_ptr<SGReaderWriterOptions> opt; osg::ref_ptr<SGReaderWriterOptions> opt;
opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions());
@ -199,9 +203,10 @@ SGModelLib::loadPagedModel(SGPropertyNode *prop_root, SGModelData *data, SGModel
unsigned int simple_models = 0; unsigned int simple_models = 0;
osg::PagedLOD *plod = new osg::PagedLOD; osg::PagedLOD *plod = new osg::PagedLOD;
// establish the error report context so we can attribute any load simgear::ErrorReportContext ec;
// errors correctly if (data) {
simgear::ErrorReportContext ec(data->getErrorContext()); ec.addFromMap(data->getErrorContext());
}
osg::ref_ptr<SGReaderWriterOptions> opt; osg::ref_ptr<SGReaderWriterOptions> opt;
opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions());