summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2024-01-03 22:57:28 +0200
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2024-03-05 00:29:35 +0200
commit78ce375dda587cbc86ade15a4d564a469e6db9d3 (patch)
tree9b1ae5e2beb4adc6afa29f28a1678cb42eab0a55 /indra/llcommon
parent1013ea51a88aba820d41db7fc259296291504c11 (diff)
SL-17896 Don't crash silently if files are missing or out of memory
Under debug LL_ERRS will show a message as well, but release won't show anything and will quit silently so show a notification when applicable.
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llcoros.cpp1
-rw-r--r--indra/llcommon/llerror.cpp42
-rw-r--r--indra/llcommon/llerror.h23
-rw-r--r--indra/llcommon/llexception.cpp1
4 files changed, 67 insertions, 0 deletions
diff --git a/indra/llcommon/llcoros.cpp b/indra/llcommon/llcoros.cpp
index 3ab97b557f..1d383f174d 100644
--- a/indra/llcommon/llcoros.cpp
+++ b/indra/llcommon/llcoros.cpp
@@ -278,6 +278,7 @@ std::string LLCoros::launch(const std::string& prefix, const callable_t& callabl
catch (std::bad_alloc&)
{
// Out of memory on stack allocation?
+ LLError::LLUserWarningMsg::showOutOfMemory();
printActiveCoroutines();
LL_ERRS("LLCoros") << "Bad memory allocation in LLCoros::launch(" << prefix << ")!" << LL_ENDL;
}
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 414515854a..3de641fcba 100644
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -1601,6 +1601,48 @@ namespace LLError
{
return out << boost::stacktrace::stacktrace();
}
+
+ // LLOutOfMemoryWarning
+ std::string LLUserWarningMsg::sLocalizedOutOfMemoryTitle;
+ std::string LLUserWarningMsg::sLocalizedOutOfMemoryWarning;
+ LLUserWarningMsg::Handler LLUserWarningMsg::sHandler;
+
+ void LLUserWarningMsg::show(const std::string& message)
+ {
+ if (sHandler)
+ {
+ sHandler(std::string(), message);
+ }
+ }
+
+ void LLUserWarningMsg::showOutOfMemory()
+ {
+ if (sHandler && !sLocalizedOutOfMemoryTitle.empty())
+ {
+ sHandler(sLocalizedOutOfMemoryTitle, sLocalizedOutOfMemoryWarning);
+ }
+ }
+
+ void LLUserWarningMsg::showMissingFiles()
+ {
+ // Files Are missing, likely can't localize.
+ const std::string error_string =
+ "Second Life viewer couldn't access some of the files it needs and will be closed."
+ "\n\nPlease reinstall viewer from https://secondlife.com/support/downloads/ and "
+ "contact https://support.secondlife.com if issue persists after reinstall.";
+ sHandler("Missing Files", error_string);
+ }
+
+ void LLUserWarningMsg::setHandler(const LLUserWarningMsg::Handler &handler)
+ {
+ sHandler = handler;
+ }
+
+ void LLUserWarningMsg::setOutOfMemoryStrings(const std::string& title, const std::string& message)
+ {
+ sLocalizedOutOfMemoryTitle = title;
+ sLocalizedOutOfMemoryWarning = message;
+ }
}
void crashdriver(void (*callback)(int*))
diff --git a/indra/llcommon/llerror.h b/indra/llcommon/llerror.h
index 05dd88ee51..6f6b349cf5 100644
--- a/indra/llcommon/llerror.h
+++ b/indra/llcommon/llerror.h
@@ -39,6 +39,7 @@
#include "llpreprocessor.h"
#include <boost/static_assert.hpp>
+#include <functional> // std::function
const int LL_ERR_NOERR = 0;
@@ -301,6 +302,28 @@ namespace LLError
{
friend std::ostream& operator<<(std::ostream& out, const LLStacktrace&);
};
+
+ // Provides access to OS notification popup on error, since
+ // not everything has access to OS's messages
+ class LLUserWarningMsg
+ {
+ public:
+ typedef std::function<void(const std::string&, const std::string&)> Handler;
+ static void setHandler(const Handler&);
+ static void setOutOfMemoryStrings(const std::string& title, const std::string& message);
+
+ // When viewer encounters bad alloc or can't access files try warning user about reasons
+ static void showOutOfMemory();
+ static void showMissingFiles();
+ // Genering error
+ static void show(const std::string&);
+
+ private:
+ // needs to be preallocated before viewer runs out of memory
+ static std::string sLocalizedOutOfMemoryTitle;
+ static std::string sLocalizedOutOfMemoryWarning;
+ static Handler sHandler;
+ };
}
//this is cheaper than llcallstacks if no need to output other variables to call stacks.
diff --git a/indra/llcommon/llexception.cpp b/indra/llcommon/llexception.cpp
index 46560b5e4c..0787bde57f 100644
--- a/indra/llcommon/llexception.cpp
+++ b/indra/llcommon/llexception.cpp
@@ -37,6 +37,7 @@
#include "llerror.h"
#include "llerrorcontrol.h"
+
// used to attach and extract stacktrace information to/from boost::exception,
// see https://www.boost.org/doc/libs/release/doc/html/stacktrace/getting_started.html#stacktrace.getting_started.exceptions_with_stacktrace
// apparently the struct passed as the first template param needs no definition?