diff --git a/simgear/debug/ErrorReportingCallback.cxx b/simgear/debug/ErrorReportingCallback.cxx index 13f1d1f4..2cea927f 100644 --- a/simgear/debug/ErrorReportingCallback.cxx +++ b/simgear/debug/ErrorReportingCallback.cxx @@ -78,17 +78,31 @@ void setErrorContextCallback(ContextCallback cb) static_contextCallback = cb; } -ErrorReportContext::ErrorReportContext(const std::string& key, const std::string& value) : _key(key) +ErrorReportContext::ErrorReportContext(const std::string& key, const std::string& value) { if (static_contextCallback) { + _keys.push_back(key); static_contextCallback(key, value); } } +ErrorReportContext::ErrorReportContext(const ContextMap& context) +{ + if (static_contextCallback) { + for (const auto& p : context) { + _keys.push_back(p.first); + static_contextCallback(p.first, p.second); + } + } +} + ErrorReportContext::~ErrorReportContext() { if (static_contextCallback) { - static_contextCallback(_key, "POP"); + // pop all our keys + for (const auto& k : _keys) { + static_contextCallback(k, "POP"); + } } } diff --git a/simgear/debug/ErrorReportingCallback.hxx b/simgear/debug/ErrorReportingCallback.hxx index 2a2a210a..6866029e 100644 --- a/simgear/debug/ErrorReportingCallback.hxx +++ b/simgear/debug/ErrorReportingCallback.hxx @@ -16,7 +16,9 @@ #pragma once #include +#include #include +#include #include @@ -70,10 +72,18 @@ class ErrorReportContext { public: ErrorReportContext(const std::string& key, const std::string& value); + + using ContextMap = std::map; + + /** + Allow establishing multiple context values in a single operation + */ + ErrorReportContext(const ContextMap& context); + ~ErrorReportContext(); private: - const std::string _key; + std::vector _keys; }; /** diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx index 1dd32459..ad0e07b9 100644 --- a/simgear/scene/model/modellib.cxx +++ b/simgear/scene/model/modellib.cxx @@ -29,12 +29,13 @@ #include #include +#include +#include #include #include -#include #include +#include #include -#include #include "SGReaderWriterXML.hxx" @@ -140,6 +141,10 @@ SGModelLib::loadModel(const string &path, opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); opt->setModelData(data); + // establish the error report context so we can attribute any load + // errors correctly + simgear::ErrorReportContext ec(data->getErrorContext()); + if (load2DPanels) { opt->setLoadPanel(static_panelFunc); } @@ -159,6 +164,9 @@ SGModelLib::loadDeferredModel(const string &path, SGPropertyNode *prop_root, proxyNode->setLoadingExternalReferenceMode(osg::ProxyNode::DEFER_LOADING_TO_DATABASE_PAGER); proxyNode->setFileName(0, path); + // establish the error report context so we can attribute any load + // errors correctly + simgear::ErrorReportContext ec(data->getErrorContext()); osg::ref_ptr opt; opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); @@ -191,6 +199,10 @@ SGModelLib::loadPagedModel(SGPropertyNode *prop_root, SGModelData *data, SGModel unsigned int simple_models = 0; osg::PagedLOD *plod = new osg::PagedLOD; + // establish the error report context so we can attribute any load + // errors correctly + simgear::ErrorReportContext ec(data->getErrorContext()); + osg::ref_ptr opt; opt = SGReaderWriterOptions::copyOrCreate(osgDB::Registry::instance()->getOptions()); opt->setPropertyNode(prop_root ? prop_root: static_propRoot.get()); diff --git a/simgear/scene/model/modellib.hxx b/simgear/scene/model/modellib.hxx index 6032bb1e..c4ba04b6 100644 --- a/simgear/scene/model/modellib.hxx +++ b/simgear/scene/model/modellib.hxx @@ -18,12 +18,9 @@ #ifndef _SG_MODEL_LIB_HXX #define _SG_MODEL_LIB_HXX 1 -#ifndef __cplusplus -# error This library requires C++ -#endif - #include // for SG_USING_STD +#include #include #include @@ -112,6 +109,10 @@ public: virtual void modelLoaded(const std::string& path, SGPropertyNode *prop, osg::Node* branch) = 0; virtual SGModelData* clone() const = 0; + + using ErrorContext = std::map; + + virtual ErrorContext getErrorContext() const = 0; }; /*