1
0
Fork 0

Attempt to log bad allocation errors at source

Use a std::set_new_handler to capture allocation failures at their
origin, instead of in the main loop exception handler
This commit is contained in:
James Turner 2020-12-17 12:37:49 +00:00
parent 7214d95040
commit 3e9a9e3730

View file

@ -219,6 +219,21 @@ void sentrySimgearReportCallback(const string& msg, const string& more, bool isF
sentry_capture_event(event); sentry_capture_event(event);
} }
void sentryReportBadAlloc()
{
sentry_value_t sentryMessage = sentry_value_new_object();
sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Fatal Error"));
sentry_value_set_by_key(sentryMessage, "formatted", sentry_value_new_string("bad allocation"));
sentry_value_t event = sentry_value_new_event();
sentry_value_set_by_key(event, "message", sentryMessage);
sentry_event_value_add_stacktrace(event, nullptr, 0);
sentry_capture_event(event);
std::set_new_handler(nullptr);
}
} // namespace } // namespace
namespace flightgear namespace flightgear
@ -334,6 +349,8 @@ void initSentry()
sglog().addCallback(new SentryLogCallback); sglog().addCallback(new SentryLogCallback);
setThrowCallback(sentryTraceSimgearThrow); setThrowCallback(sentryTraceSimgearThrow);
simgear::setErrorReportCallback(sentrySimgearReportCallback); simgear::setErrorReportCallback(sentrySimgearReportCallback);
std::set_new_handler(sentryReportBadAlloc);
} }
void delayedSentryInit() void delayedSentryInit()