Control over reporting from SimGear

To avoid exposign Sentry to Simgear, add some abstract reporting controls
which can be toggled easily without any extra dependencies.
This commit is contained in:
James Turner 2021-07-31 17:19:55 +01:00
parent b44f187328
commit d8874c26b6
7 changed files with 52 additions and 1 deletions

View File

@ -4,11 +4,13 @@ include (SimGearComponent)
set(HEADERS debug_types.h
logstream.hxx BufferedLogCallback.hxx OsgIoCapture.hxx
LogCallback.hxx LogEntry.hxx
ErrorReportingCallback.hxx logdelta.hxx)
ErrorReportingCallback.hxx logdelta.hxx
Reporting.hxx)
set(SOURCES logstream.cxx BufferedLogCallback.cxx
LogCallback.cxx LogEntry.cxx logdelta.cxx
ErrorReportingCallback.cxx
Reporting.cxx
)
simgear_component(debug debug "${SOURCES}" "${HEADERS}")

View File

@ -0,0 +1,24 @@
#include "Reporting.hxx"
namespace simgear
{
thread_local bool perThread_reportBadAlloc = true;
ReportBadAllocGuard::ReportBadAllocGuard()
{
perThread_reportBadAlloc = false;
}
ReportBadAllocGuard::~ReportBadAllocGuard()
{
perThread_reportBadAlloc = true;
}
bool ReportBadAllocGuard::isSet()
{
return perThread_reportBadAlloc;
}
}

View File

@ -0,0 +1,16 @@
#pragma once
namespace simgear
{
class ReportBadAllocGuard
{
public:
ReportBadAllocGuard();
~ReportBadAllocGuard();
static bool isSet();
};
}

View File

@ -36,6 +36,8 @@
#include "simgear/misc/strutils.hxx"
#include <simgear/debug/ErrorReportingCallback.hxx>
#include <simgear/debug/Reporting.hxx>
#include <simgear/io/HTTPClient.hxx>
#include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/io/sg_file.hxx>
@ -244,6 +246,7 @@ public:
const size_t sizeToCopy = cp.sizeInBytes();
if (buf.size() < sizeToCopy) {
try {
simgear::ReportBadAllocGuard g;
buf.resize(sizeToCopy);
} catch (std::bad_alloc&) {
simgear::reportFailure(simgear::LoadFailure::OutOfMemory, simgear::ErrorCode::TerraSync,

View File

@ -57,6 +57,7 @@
#include <simgear/scene/util/SGTextureStateAttributeVisitor.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/scene/util/NodeAndDrawableVisitor.hxx>
#include <simgear/debug/Reporting.hxx>
#include <simgear/scene/tgdb/VPBTechnique.hxx>
@ -560,6 +561,7 @@ ModelRegistry::readImage(const string& fileName,
}
try {
simgear::ReportBadAllocGuard g;
// REVIEW: Memory Leak - 262,144 bytes in 1 blocks are indirectly lost
// The leak occurs with OSG, but may be related to opt being a raw pointer
res = registry->readImageImplementation(absFileName, opt);

View File

@ -23,6 +23,7 @@
#include <osgDB/Registry>
#include <simgear/debug/ErrorReportingCallback.hxx>
#include <simgear/debug/Reporting.hxx>
#include <simgear/scene/model/ModelRegistry.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/structure/exception.hxx>
@ -65,6 +66,7 @@ SGReaderWriterBTG::readNode(const std::string& fileName,
osg::Node* result = NULL;
simgear::ErrorReportContext ec{"btg", fileName};
try {
simgear::ReportBadAllocGuard g;
result = SGLoadBTG(fileName, sgOptions);
if (!result)
return ReadResult::FILE_NOT_HANDLED;

View File

@ -32,6 +32,7 @@
#include "SGSmplstat.hxx"
#include <simgear/debug/ErrorReportingCallback.hxx>
#include <simgear/debug/Reporting.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/props/props.hxx>
@ -840,6 +841,7 @@ SGSubsystemGroup::Member::update (double delta_time_sec)
return;
}
simgear::ReportBadAllocGuard bg;
SGTimeStamp oTimer;
try {
oTimer.stamp();