From 3817bdd6025f1cd7868b7eaaa4da9bb0fc49d114 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Wed, 18 Jul 2018 10:28:56 +0200 Subject: [PATCH] NotifyLogger: Shifted the class from flightgear to simgear. This is to allow the code to be reused in the flightgear test suite. --- simgear/debug/CMakeLists.txt | 4 +-- simgear/debug/OsgIoCapture.hxx | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 simgear/debug/OsgIoCapture.hxx diff --git a/simgear/debug/CMakeLists.txt b/simgear/debug/CMakeLists.txt index 07690068..e494eb92 100644 --- a/simgear/debug/CMakeLists.txt +++ b/simgear/debug/CMakeLists.txt @@ -1,7 +1,7 @@ include (SimGearComponent) -set(HEADERS debug_types.h logstream.hxx BufferedLogCallback.hxx) +set(HEADERS debug_types.h logstream.hxx BufferedLogCallback.hxx OsgIoCapture.hxx) set(SOURCES logstream.cxx BufferedLogCallback.cxx) -simgear_component(debug debug "${SOURCES}" "${HEADERS}") \ No newline at end of file +simgear_component(debug debug "${SOURCES}" "${HEADERS}") diff --git a/simgear/debug/OsgIoCapture.hxx b/simgear/debug/OsgIoCapture.hxx new file mode 100644 index 00000000..7804dda2 --- /dev/null +++ b/simgear/debug/OsgIoCapture.hxx @@ -0,0 +1,45 @@ +#include + +#include + +using namespace osg; + + +/** + * merge OSG output into our logging system, so it gets recorded to file, + * and so we can display a GUI console with renderer issues, especially + * shader compilation warnings and errors. + */ +class NotifyLogger : public osg::NotifyHandler +{ +public: + // note this callback will be invoked by OSG from multiple threads. + // fortunately our Simgear logging implementation already handles + // that internally, so we simply pass the message on. + virtual void notify(osg::NotifySeverity severity, const char* message) { + // Detect whether a osg::Reference derived object is deleted with a non-zero + // reference count. In this case trigger a segfault to get a stack trace. + if (strstr(message, "the final reference count was")) { + // as this is going to segfault ignore the translation of severity and always output the message. + SG_LOG(SG_GL, SG_ALERT, message); + int* trigger_segfault = 0; + *trigger_segfault = 0; + return; + } + SG_LOG(SG_GL, translateSeverity(severity), message); + } + +private: + sgDebugPriority translateSeverity(osg::NotifySeverity severity) { + switch (severity) { + case osg::ALWAYS: + case osg::FATAL: return SG_ALERT; + case osg::WARN: return SG_WARN; + case osg::NOTICE: + case osg::INFO: return SG_INFO; + case osg::DEBUG_FP: + case osg::DEBUG_INFO: return SG_DEBUG; + default: return SG_ALERT; + } + } +};