Skip to content

Commit 374eea4

Browse files
committed
viewer#3088 Report out of memory as a separate 'category'
1 parent 916a8fd commit 374eea4

File tree

6 files changed

+131
-29
lines changed

6 files changed

+131
-29
lines changed

indra/llcommon/llerror.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,19 +1607,19 @@ namespace LLError
16071607
std::string LLUserWarningMsg::sLocalizedOutOfMemoryWarning;
16081608
LLUserWarningMsg::Handler LLUserWarningMsg::sHandler;
16091609

1610-
void LLUserWarningMsg::show(const std::string& message)
1610+
void LLUserWarningMsg::show(const std::string& message, S32 error_code)
16111611
{
16121612
if (sHandler)
16131613
{
1614-
sHandler(std::string(), message);
1614+
sHandler(std::string(), message, error_code);
16151615
}
16161616
}
16171617

16181618
void LLUserWarningMsg::showOutOfMemory()
16191619
{
16201620
if (sHandler && !sLocalizedOutOfMemoryTitle.empty())
16211621
{
1622-
sHandler(sLocalizedOutOfMemoryTitle, sLocalizedOutOfMemoryWarning);
1622+
sHandler(sLocalizedOutOfMemoryTitle, sLocalizedOutOfMemoryWarning, ERROR_BAD_ALLOC);
16231623
}
16241624
}
16251625

@@ -1630,7 +1630,7 @@ namespace LLError
16301630
"Second Life viewer couldn't access some of the files it needs and will be closed."
16311631
"\n\nPlease reinstall viewer from https://secondlife.com/support/downloads/ and "
16321632
"contact https://support.secondlife.com if issue persists after reinstall.";
1633-
sHandler("Missing Files", error_string);
1633+
sHandler("Missing Files", error_string, ERROR_MISSING_FILES);
16341634
}
16351635

16361636
void LLUserWarningMsg::setHandler(const LLUserWarningMsg::Handler &handler)

indra/llcommon/llerror.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,23 @@ namespace LLError
308308
class LLUserWarningMsg
309309
{
310310
public:
311-
typedef std::function<void(const std::string&, const std::string&)> Handler;
311+
typedef enum
312+
{
313+
ERROR_OTHER = 0,
314+
ERROR_BAD_ALLOC = 1,
315+
ERROR_MISSING_FILES = 2,
316+
} eLastExecEvent;
317+
318+
// tittle, message and error code to include in error marker file
319+
typedef std::function<void(const std::string&, const std::string&, S32 error_code)> Handler;
312320
static void setHandler(const Handler&);
313321
static void setOutOfMemoryStrings(const std::string& title, const std::string& message);
314322

315323
// When viewer encounters bad alloc or can't access files try warning user about reasons
316324
static void showOutOfMemory();
317325
static void showMissingFiles();
318326
// Genering error
319-
static void show(const std::string&);
327+
static void show(const std::string&, S32 error_code = -1);
320328

321329
private:
322330
// needs to be preallocated before viewer runs out of memory

indra/llui/llnotifications.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ bool LLNotifications::loadTemplates()
15551555
gDirUtilp->findSkinnedFilenames(LLDir::XUI, "notifications.xml", LLDir::ALL_SKINS);
15561556
if (search_paths.empty())
15571557
{
1558-
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"));
1558+
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"), LLError::LLUserWarningMsg::ERROR_MISSING_FILES);
15591559
LL_ERRS() << "Problem finding notifications.xml" << LL_ENDL;
15601560
}
15611561

@@ -1565,7 +1565,7 @@ bool LLNotifications::loadTemplates()
15651565

15661566
if (!success || root.isNull() || !root->hasName( "notifications" ))
15671567
{
1568-
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"));
1568+
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"), LLError::LLUserWarningMsg::ERROR_MISSING_FILES);
15691569
LL_ERRS() << "Problem reading XML from UI Notifications file: " << base_filename << LL_ENDL;
15701570
return false;
15711571
}
@@ -1576,7 +1576,7 @@ bool LLNotifications::loadTemplates()
15761576

15771577
if(!params.validateBlock())
15781578
{
1579-
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"));
1579+
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"), LLError::LLUserWarningMsg::ERROR_MISSING_FILES);
15801580
LL_ERRS() << "Problem reading XUI from UI Notifications file: " << base_filename << LL_ENDL;
15811581
return false;
15821582
}
@@ -1643,7 +1643,7 @@ bool LLNotifications::loadVisibilityRules()
16431643

16441644
if(!params.validateBlock())
16451645
{
1646-
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"));
1646+
LLError::LLUserWarningMsg::show(LLTrans::getString("MBMissingFile"), LLError::LLUserWarningMsg::ERROR_MISSING_FILES);
16471647
LL_ERRS() << "Problem reading UI Notification Visibility Rules file: " << full_filename << LL_ENDL;
16481648
return false;
16491649
}

indra/llui/lltransutil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool LLTransUtil::parseStrings(const std::string& xml_filename, const std::set<s
4848
"Second Life viewer couldn't access some of the files it needs and will be closed."
4949
"\n\nPlease reinstall viewer from https://secondlife.com/support/downloads/ and "
5050
"contact https://support.secondlife.com if issue persists after reinstall.";
51-
LLError::LLUserWarningMsg::show(error_string);
51+
LLError::LLUserWarningMsg::show(error_string, LLError::LLUserWarningMsg::ERROR_MISSING_FILES);
5252
gDirUtilp->dumpCurrentDirectories(LLError::LEVEL_WARN);
5353
LL_ERRS() << "Couldn't load string table " << xml_filename << " " << errno << LL_ENDL;
5454
return false;

indra/newview/llappviewer.cpp

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,12 +2345,26 @@ void errorCallback(LLError::ELevel level, const std::string &error_string)
23452345
}
23462346
}
23472347

2348-
void errorMSG(const std::string& title_string, const std::string& message_string)
2348+
void errorHandler(const std::string& title_string, const std::string& message_string, S32 code)
23492349
{
23502350
if (!message_string.empty())
23512351
{
23522352
OSMessageBox(message_string, title_string.empty() ? LLTrans::getString("MBFatalError") : title_string, OSMB_OK);
23532353
}
2354+
switch (code)
2355+
{
2356+
case LLError::LLUserWarningMsg::ERROR_OTHER:
2357+
LLAppViewer::instance()->createErrorMarker(LAST_EXEC_OTHER_CRASH);
2358+
break;
2359+
case LLError::LLUserWarningMsg::ERROR_BAD_ALLOC:
2360+
LLAppViewer::instance()->createErrorMarker(LAST_EXEC_BAD_ALLOC);
2361+
break;
2362+
case LLError::LLUserWarningMsg::ERROR_MISSING_FILES:
2363+
LLAppViewer::instance()->createErrorMarker(LAST_EXEC_MISSING_FILES);
2364+
break;
2365+
default:
2366+
break;
2367+
}
23542368
}
23552369

23562370
void LLAppViewer::initLoggingAndGetLastDuration()
@@ -2364,7 +2378,7 @@ void LLAppViewer::initLoggingAndGetLastDuration()
23642378
LLError::addGenericRecorder(&errorCallback);
23652379
//LLError::setTimeFunction(getRuntime);
23662380

2367-
LLError::LLUserWarningMsg::setHandler(errorMSG);
2381+
LLError::LLUserWarningMsg::setHandler(errorHandler);
23682382

23692383

23702384
if (mSecondInstance)
@@ -3823,16 +3837,21 @@ bool LLAppViewer::markerIsSameVersion(const std::string& marker_name) const
38233837
bool sameVersion = false;
38243838

38253839
std::string my_version(LLVersionInfo::instance().getChannelAndVersion());
3826-
char marker_version[MAX_MARKER_LENGTH];
3840+
char marker_data[MAX_MARKER_LENGTH];
38273841
S32 marker_version_length;
38283842

38293843
LLAPRFile marker_file;
38303844
marker_file.open(marker_name, LL_APR_RB);
38313845
if (marker_file.getFileHandle())
38323846
{
3833-
marker_version_length = marker_file.read(marker_version, sizeof(marker_version));
3834-
std::string marker_string(marker_version, marker_version_length);
3835-
if ( 0 == my_version.compare( 0, my_version.length(), marker_version, 0, marker_version_length ) )
3847+
marker_version_length = marker_file.read(marker_data, sizeof(marker_data));
3848+
std::string marker_string(marker_data, marker_version_length);
3849+
size_t pos = marker_string.find('\n');
3850+
if (pos != std::string::npos)
3851+
{
3852+
marker_string = marker_string.substr(0, pos);
3853+
}
3854+
if ( 0 == my_version.compare( 0, my_version.length(), marker_string, 0, marker_string.length()) )
38363855
{
38373856
sameVersion = true;
38383857
}
@@ -3846,6 +3865,50 @@ bool LLAppViewer::markerIsSameVersion(const std::string& marker_name) const
38463865
return sameVersion;
38473866
}
38483867

3868+
S32 LLAppViewer::getMarkerData(const std::string& marker_name) const
3869+
{
3870+
bool sameVersion = false;
3871+
3872+
std::string my_version(LLVersionInfo::instance().getChannelAndVersion());
3873+
char marker_data[MAX_MARKER_LENGTH];
3874+
S32 marker_version_length;
3875+
3876+
LLAPRFile marker_file;
3877+
marker_file.open(marker_name, LL_APR_RB);
3878+
if (marker_file.getFileHandle())
3879+
{
3880+
marker_version_length = marker_file.read(marker_data, sizeof(marker_data));
3881+
marker_file.close();
3882+
std::string marker_string(marker_data, marker_version_length);
3883+
std::string data;
3884+
size_t pos = marker_string.find('\n');
3885+
if (pos != std::string::npos)
3886+
{
3887+
data = marker_string.substr(pos + 1, marker_version_length - pos - 1);
3888+
marker_string = marker_string.substr(0, pos);
3889+
}
3890+
if (0 == my_version.compare(0, my_version.length(), marker_string, 0, marker_string.length()))
3891+
{
3892+
sameVersion = true;
3893+
}
3894+
else
3895+
{
3896+
return -1;
3897+
}
3898+
LL_DEBUGS("MarkerFile") << "Compare markers for '" << marker_name << "': "
3899+
<< "\n mine '" << my_version << "'"
3900+
<< "\n marker '" << marker_string << "'"
3901+
<< "\n " << (sameVersion ? "same" : "different") << " version"
3902+
<< LL_ENDL;
3903+
if (data.length() == 0)
3904+
{
3905+
return 0;
3906+
}
3907+
return std::stoi(data);
3908+
}
3909+
return -1;
3910+
}
3911+
38493912
void LLAppViewer::processMarkerFiles()
38503913
{
38513914
//We've got 4 things to test for here
@@ -3980,17 +4043,23 @@ void LLAppViewer::processMarkerFiles()
39804043
std::string error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME);
39814044
if(LLAPRFile::isExist(error_marker_file, NULL, LL_APR_RB))
39824045
{
3983-
if (markerIsSameVersion(error_marker_file))
4046+
S32 marker_code = getMarkerData(error_marker_file);
4047+
if (marker_code >= 0)
39844048
{
39854049
if (gLastExecEvent == LAST_EXEC_LOGOUT_FROZE)
39864050
{
39874051
gLastExecEvent = LAST_EXEC_LOGOUT_CRASH;
39884052
LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to LOGOUT_CRASH" << LL_ENDL;
39894053
}
4054+
else if (marker_code > 0 && marker_code < (S32)LAST_EXEC_COUNT)
4055+
{
4056+
gLastExecEvent = (eLastExecEvent)marker_code;
4057+
LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to " << gLastExecEvent << LL_ENDL;
4058+
}
39904059
else
39914060
{
39924061
gLastExecEvent = LAST_EXEC_OTHER_CRASH;
3993-
LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to " << gLastExecEvent << LL_ENDL;
4062+
LL_INFOS("MarkerFile") << "Error marker '" << error_marker_file << "' crashed, setting LastExecEvent to " << gLastExecEvent << LL_ENDL;
39944063
}
39954064
}
39964065
else
@@ -5321,6 +5390,24 @@ void LLAppViewer::postToMainCoro(const LL::WorkQueue::Work& work)
53215390
gMainloopWork.post(work);
53225391
}
53235392

5393+
void LLAppViewer::createErrorMarker(eLastExecEvent error_code) const
5394+
{
5395+
if (!mSecondInstance)
5396+
{
5397+
std::string error_marker = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME);
5398+
5399+
LLAPRFile file;
5400+
file.open(error_marker, LL_APR_WB);
5401+
if (file.getFileHandle())
5402+
{
5403+
recordMarkerVersion(file);
5404+
std::string data = "\n" + std::to_string((S32)error_code);
5405+
file.write(data.data(), static_cast<S32>(data.length()));
5406+
file.close();
5407+
}
5408+
}
5409+
}
5410+
53245411
void LLAppViewer::outOfMemorySoftQuit()
53255412
{
53265413
if (!mQuitRequested)

indra/newview/llappviewer.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class LLViewerRegion;
6666

6767
extern LLTrace::BlockTimerStatHandle FTM_FRAME;
6868

69+
typedef enum
70+
{
71+
LAST_EXEC_NORMAL = 0,
72+
LAST_EXEC_FROZE,
73+
LAST_EXEC_LLERROR_CRASH,
74+
LAST_EXEC_OTHER_CRASH,
75+
LAST_EXEC_LOGOUT_FROZE,
76+
LAST_EXEC_LOGOUT_CRASH,
77+
LAST_EXEC_BAD_ALLOC,
78+
LAST_EXEC_MISSING_FILES,
79+
LAST_EXEC_COUNT
80+
} eLastExecEvent;
81+
6982
class LLAppViewer : public LLApp
7083
{
7184
public:
@@ -227,6 +240,9 @@ class LLAppViewer : public LLApp
227240
// post given work to the "mainloop" work queue for handling on the main thread
228241
void postToMainCoro(const LL::WorkQueue::Work& work);
229242

243+
// Writes an error code into the error_marker file for use on next startup.
244+
void createErrorMarker(eLastExecEvent error_code) const;
245+
230246
// Attempt a 'soft' quit with disconnect and saving of settings/cache.
231247
// Intended to be thread safe.
232248
// Good chance of viewer crashing either way, but better than alternatives.
@@ -272,6 +288,7 @@ class LLAppViewer : public LLApp
272288
void processMarkerFiles();
273289
static void recordMarkerVersion(LLAPRFile& marker_file);
274290
bool markerIsSameVersion(const std::string& marker_name) const;
291+
S32 getMarkerData(const std::string& marker_name) const;
275292

276293
void idle();
277294
void idleShutdown();
@@ -347,16 +364,6 @@ class LLAppViewer : public LLApp
347364
extern LLSD gDebugInfo;
348365
extern bool gShowObjectUpdates;
349366

350-
typedef enum
351-
{
352-
LAST_EXEC_NORMAL = 0,
353-
LAST_EXEC_FROZE,
354-
LAST_EXEC_LLERROR_CRASH,
355-
LAST_EXEC_OTHER_CRASH,
356-
LAST_EXEC_LOGOUT_FROZE,
357-
LAST_EXEC_LOGOUT_CRASH
358-
} eLastExecEvent;
359-
360367
extern eLastExecEvent gLastExecEvent; // llstartup
361368
extern S32 gLastExecDuration; ///< the duration of the previous run in seconds (<0 indicates unknown)
362369

0 commit comments

Comments
 (0)