From 72b1cfc76b6deda8771935b086f040b887ffe804 Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Wed, 9 Nov 2022 14:42:27 +0200
Subject: [PATCH] SL-18586 FIXED Crash when opening 360 snapshot

---
 doc/contributions.txt                 |  1 +
 indra/newview/llfloater360capture.cpp | 11 +----------
 indra/newview/llperfstats.cpp         |  6 +++++-
 indra/newview/llperfstats.h           |  8 +++++---
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index b0d54b23c9c..14cf503df2d 100755
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -283,6 +283,7 @@ Beq Janus
 	SL-15709
 	SL-16021
 	SL-18202
+	SL-18586
 Beth Walcher
 Bezilon Kasei
 Biancaluce Robbiani
diff --git a/indra/newview/llfloater360capture.cpp b/indra/newview/llfloater360capture.cpp
index c075f7e8bdd..a70cd903c52 100644
--- a/indra/newview/llfloater360capture.cpp
+++ b/indra/newview/llfloater360capture.cpp
@@ -319,13 +319,7 @@ const std::string LLFloater360Capture::getHTMLBaseFolder()
 // triggered when the 'capture' button in the UI is pressed
 void LLFloater360Capture::onCapture360ImagesBtn()
 {
-    // launch the main capture code in a coroutine so we can
-    // yield/suspend at some points to give the main UI
-    // thread a look-in occasionally.
-    LLCoros::instance().launch("capture360cap", [this]()
-    {
-        capture360Images();
-    });
+    capture360Images();
 }
 
 // Gets the full path name for a given JavaScript file in the HTML folder. We
@@ -680,9 +674,6 @@ void LLFloater360Capture::capture360Images()
     mCaptureBtn->setEnabled(true);
     mSaveLocalBtn->setEnabled(true);
 
-    // allow the UI to update by suspending and waiting for the
-    // main render loop to update the UI
-    suspendForAFrame();
 }
 
 // once the request is made to navigate to the web page containing the code
diff --git a/indra/newview/llperfstats.cpp b/indra/newview/llperfstats.cpp
index 1a0e5842e2d..3bf88bb2a69 100644
--- a/indra/newview/llperfstats.cpp
+++ b/indra/newview/llperfstats.cpp
@@ -43,6 +43,8 @@ namespace LLPerfStats
     U32 lastGlobalPrefChange{0}; 
     std::mutex bufferToggleLock{};
 
+    F64 cpu_hertz{0.0};
+
     Tunables tunables;
 
     std::atomic<int> 	StatsRecorder::writeBuffer{0};
@@ -126,6 +128,8 @@ namespace LLPerfStats
         // create a queue
         // create a thread to consume from the queue
         tunables.initialiseFromSettings();
+        LLPerfStats::cpu_hertz = (F64)LLTrace::BlockTimer::countsPerSecond();
+
         t.detach();
     }
 
@@ -332,7 +336,7 @@ namespace LLPerfStats
         }
 
         // The frametime budget we have based on the target FPS selected
-        auto target_frame_time_raw = (U64)llround((F64)LLTrace::BlockTimer::countsPerSecond()/(tunables.userTargetFPS==0?1:tunables.userTargetFPS));
+        auto target_frame_time_raw = (U64)llround(LLPerfStats::cpu_hertz/(tunables.userTargetFPS==0?1:tunables.userTargetFPS));
         // LL_INFOS() << "Effective FPS(raw):" << tot_frame_time_raw << " Target:" << target_frame_time_raw << LL_ENDL;
         auto inferredFPS{1000/(U32)std::max(raw_to_ms(tot_frame_time_raw),1.0)};
         U32 settingsChangeFrequency{inferredFPS > 25?inferredFPS:25};
diff --git a/indra/newview/llperfstats.h b/indra/newview/llperfstats.h
index 961594f18cc..ac44afe5db3 100644
--- a/indra/newview/llperfstats.h
+++ b/indra/newview/llperfstats.h
@@ -55,6 +55,8 @@ namespace LLPerfStats
     static constexpr U32 TUNE_AVATARS_ONLY{0};
     static constexpr U32 TUNE_SCENE_AND_AVATARS{1};
 
+    extern F64 cpu_hertz;
+
     extern std::atomic<int64_t> tunedAvatars;
     extern std::atomic<U64> renderAvatarMaxART_ns;
     extern bool belowTargetFPS;
@@ -398,9 +400,9 @@ namespace LLPerfStats
     };
 
     
-    inline double raw_to_ns(U64 raw)    { return (static_cast<double>(raw) * 1000000000.0) / (F64)LLTrace::BlockTimer::countsPerSecond(); };
-    inline double raw_to_us(U64 raw)    { return (static_cast<double>(raw) *    1000000.0) / (F64)LLTrace::BlockTimer::countsPerSecond(); };
-    inline double raw_to_ms(U64 raw)    { return (static_cast<double>(raw) *       1000.0) / (F64)LLTrace::BlockTimer::countsPerSecond(); };
+    inline double raw_to_ns(U64 raw)    { return (static_cast<double>(raw) * 1000000000.0) / LLPerfStats::cpu_hertz; };
+    inline double raw_to_us(U64 raw)    { return (static_cast<double>(raw) *    1000000.0) / LLPerfStats::cpu_hertz; };
+    inline double raw_to_ms(U64 raw)    { return (static_cast<double>(raw) *       1000.0) / LLPerfStats::cpu_hertz; };
 
     using RecordSceneTime = RecordTime<ObjType_t::OT_GENERAL>;
     using RecordAvatarTime = RecordTime<ObjType_t::OT_AVATAR>;
-- 
GitLab