From 3e9a9e3730cbe027ef40094dcc6136883a8823c1 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 17 Dec 2020 12:37:49 +0000 Subject: [PATCH] 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 --- src/Main/sentryIntegration.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index c805efe3a..c3445e611 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -219,6 +219,21 @@ void sentrySimgearReportCallback(const string& msg, const string& more, bool isF 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 flightgear @@ -334,6 +349,8 @@ void initSentry() sglog().addCallback(new SentryLogCallback); setThrowCallback(sentryTraceSimgearThrow); simgear::setErrorReportCallback(sentrySimgearReportCallback); + + std::set_new_handler(sentryReportBadAlloc); } void delayedSentryInit()