From 9b2df75c87d8ef06177f1591716cbe913b66de1e Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 25 Mar 2022 13:05:50 -0500
Subject: [PATCH] SL-17077 Ensure profiling is disabled if gpu_benchmark fails.
  Log the source of the real crash for when the viewer inevitably crashes
 later.

---
 indra/llcommon/llexception.cpp     | 5 +++++
 indra/newview/llfeaturemanager.cpp | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/indra/llcommon/llexception.cpp b/indra/llcommon/llexception.cpp
index b584b0ff8b5..46560b5e4ce 100644
--- a/indra/llcommon/llexception.cpp
+++ b/indra/llcommon/llexception.cpp
@@ -97,6 +97,11 @@ static const U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific
 
 U32 msc_exception_filter(U32 code, struct _EXCEPTION_POINTERS *exception_infop)
 {
+    const auto stack = to_string(boost::stacktrace::stacktrace());
+    LL_WARNS() << "SEH Exception handled (that probably shouldn't be): Code " << code 
+        << "\n Stack trace: \n" 
+        << stack << LL_ENDL;
+
     if (code == STATUS_MSC_EXCEPTION)
     {
         // C++ exception, go on
diff --git a/indra/newview/llfeaturemanager.cpp b/indra/newview/llfeaturemanager.cpp
index 3240f169b34..e934041e2eb 100644
--- a/indra/newview/llfeaturemanager.cpp
+++ b/indra/newview/llfeaturemanager.cpp
@@ -381,7 +381,10 @@ F32 gpu_benchmark();
 
 F32 logExceptionBenchmark()
 {
-    // Todo: make a wrapper/class for SEH exceptions
+    // FIXME: gpu_benchmark uses many C++ classes on the stack to control state.
+    //  SEH exceptions with our current exception handling options do not call 
+    //  destructors for these classes, resulting in an undefined state should
+    //  this handler be invoked.  
     F32 gbps = -1;
     __try
     {
@@ -389,6 +392,9 @@ F32 logExceptionBenchmark()
     }
     __except (msc_exception_filter(GetExceptionCode(), GetExceptionInformation()))
     {
+        // HACK - ensure that profiling is disabled
+        LLGLSLShader::finishProfile(false);
+
         // convert to C++ styled exception
         char integer_string[32];
         sprintf(integer_string, "SEH, code: %lu\n", GetExceptionCode());
-- 
GitLab