aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llappviewer.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llappviewer.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/newview/llappviewer.cpp')
-rw-r--r--linden/indra/newview/llappviewer.cpp418
1 files changed, 222 insertions, 196 deletions
diff --git a/linden/indra/newview/llappviewer.cpp b/linden/indra/newview/llappviewer.cpp
index 6e8528c..6a53300 100644
--- a/linden/indra/newview/llappviewer.cpp
+++ b/linden/indra/newview/llappviewer.cpp
@@ -37,6 +37,7 @@
37#include "llversionviewer.h" 37#include "llversionviewer.h"
38#include "llfeaturemanager.h" 38#include "llfeaturemanager.h"
39#include "lluictrlfactory.h" 39#include "lluictrlfactory.h"
40#include "lltexteditor.h"
40#include "llalertdialog.h" 41#include "llalertdialog.h"
41#include "llerrorcontrol.h" 42#include "llerrorcontrol.h"
42#include "llviewerimagelist.h" 43#include "llviewerimagelist.h"
@@ -115,6 +116,7 @@
115#include "llcontainerview.h" 116#include "llcontainerview.h"
116#include "llfloaterstats.h" 117#include "llfloaterstats.h"
117#include "llhoverview.h" 118#include "llhoverview.h"
119#include "llfloatermemleak.h"
118 120
119#include "llsdserialize.h" 121#include "llsdserialize.h"
120 122
@@ -198,7 +200,6 @@ extern void init_apple_menu(const char* product);
198extern OSErr AEGURLHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn); 200extern OSErr AEGURLHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn);
199extern OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn); 201extern OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn);
200extern OSStatus simpleDialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata); 202extern OSStatus simpleDialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata);
201extern OSStatus DisplayReleaseNotes(void);
202#include <boost/tokenizer.hpp> 203#include <boost/tokenizer.hpp>
203#endif // LL_DARWIN 204#endif // LL_DARWIN
204 205
@@ -216,13 +217,13 @@ const F32 DEFAULT_AFK_TIMEOUT = 5.f * 60.f; // time with no input before user fl
216F32 gSimLastTime; // Used in LLAppViewer::init and send_stats() 217F32 gSimLastTime; // Used in LLAppViewer::init and send_stats()
217F32 gSimFrames; 218F32 gSimFrames;
218 219
219LLString gDisabledMessage; // Set in LLAppViewer::initConfiguration used in idle_startup 220std::string gDisabledMessage; // Set in LLAppViewer::initConfiguration used in idle_startup
220 221
221BOOL gHideLinks = FALSE; // Set in LLAppViewer::initConfiguration, used externally 222BOOL gHideLinks = FALSE; // Set in LLAppViewer::initConfiguration, used externally
222 223
223BOOL gAllowIdleAFK = TRUE; 224BOOL gAllowIdleAFK = TRUE;
224BOOL gAllowTapTapHoldRun = TRUE; 225BOOL gAllowTapTapHoldRun = TRUE;
225BOOL gShowObjectUpdates = FALSE; 226BOOL gShowObjectUpdates = FALSE;
226BOOL gUseQuickTime = TRUE; 227BOOL gUseQuickTime = TRUE;
227 228
228BOOL gAcceptTOS = FALSE; 229BOOL gAcceptTOS = FALSE;
@@ -234,22 +235,24 @@ LLSD gDebugInfo;
234 235
235U32 gFrameCount = 0; 236U32 gFrameCount = 0;
236U32 gForegroundFrameCount = 0; // number of frames that app window was in foreground 237U32 gForegroundFrameCount = 0; // number of frames that app window was in foreground
237LLPumpIO* gServicePump = NULL; 238LLPumpIO* gServicePump = NULL;
238 239
239BOOL gPacificDaylightTime = FALSE; 240BOOL gPacificDaylightTime = FALSE;
240 241
241U64 gFrameTime = 0; 242U64 gFrameTime = 0;
242F32 gFrameTimeSeconds = 0.f; 243F32 gFrameTimeSeconds = 0.f;
243F32 gFrameIntervalSeconds = 0.f; 244F32 gFrameIntervalSeconds = 0.f;
244F32 gFPSClamped = 10.f; // Pretend we start at target rate. 245F32 gFPSClamped = 10.f; // Pretend we start at target rate.
245F32 gFrameDTClamped = 0.f; // Time between adjacent checks to network for packets 246F32 gFrameDTClamped = 0.f; // Time between adjacent checks to network for packets
246U64 gStartTime = 0; // gStartTime is "private", used only to calculate gFrameTimeSeconds 247U64 gStartTime = 0; // gStartTime is "private", used only to calculate gFrameTimeSeconds
248U32 gFrameStalls = 0;
249const F64 FRAME_STALL_THRESHOLD = 5.0;
247 250
248LLTimer gRenderStartTime; 251LLTimer gRenderStartTime;
249LLFrameTimer gForegroundTime; 252LLFrameTimer gForegroundTime;
250LLTimer gLogoutTimer; 253LLTimer gLogoutTimer;
251static const F32 LOGOUT_REQUEST_TIME = 6.f; // this will be cut short by the LogoutReply msg. 254static const F32 LOGOUT_REQUEST_TIME = 6.f; // this will be cut short by the LogoutReply msg.
252F32 gLogoutMaxTime = LOGOUT_REQUEST_TIME; 255F32 gLogoutMaxTime = LOGOUT_REQUEST_TIME;
253 256
254LLUUID gInventoryLibraryOwner; 257LLUUID gInventoryLibraryOwner;
255LLUUID gInventoryLibraryRoot; 258LLUUID gInventoryLibraryRoot;
@@ -271,7 +274,7 @@ LLVFS* gStaticVFS = NULL;
271LLMemoryInfo gSysMemory; 274LLMemoryInfo gSysMemory;
272U64 gMemoryAllocated = 0; // updated in display_stats() in llviewerdisplay.cpp 275U64 gMemoryAllocated = 0; // updated in display_stats() in llviewerdisplay.cpp
273 276
274LLString gLastVersionChannel; 277std::string gLastVersionChannel;
275 278
276LLVector3 gWindVec(3.0, 3.0, 0.0); 279LLVector3 gWindVec(3.0, 3.0, 0.0);
277LLVector3 gRelativeWindVec(0.0, 0.0, 0.0); 280LLVector3 gRelativeWindVec(0.0, 0.0, 0.0);
@@ -289,22 +292,22 @@ BOOL gLogoutInProgress = FALSE;
289 292
290//////////////////////////////////////////////////////////// 293////////////////////////////////////////////////////////////
291// Internal globals... that should be removed. 294// Internal globals... that should be removed.
292static LLString gArgs; 295static std::string gArgs;
293 296
294const char* MARKER_FILE_NAME = "SecondLife.exec_marker"; 297const std::string MARKER_FILE_NAME("SecondLife.exec_marker");
295const char* ERROR_MARKER_FILE_NAME = "SecondLife.error_marker"; 298const std::string ERROR_MARKER_FILE_NAME("SecondLife.error_marker");
296const char* LLERROR_MARKER_FILE_NAME = "SecondLife.llerror_marker"; 299const std::string LLERROR_MARKER_FILE_NAME("SecondLife.llerror_marker");
297const char* LOGOUT_MARKER_FILE_NAME = "SecondLife.logout_marker"; 300const std::string LOGOUT_MARKER_FILE_NAME("SecondLife.logout_marker");
298static BOOL gDoDisconnect = FALSE; 301static BOOL gDoDisconnect = FALSE;
299static LLString gLaunchFileOnQuit; 302static std::string gLaunchFileOnQuit;
300 303
301//---------------------------------------------------------------------------- 304//----------------------------------------------------------------------------
302// File scope definitons 305// File scope definitons
303const char *VFS_DATA_FILE_BASE = "data.db2.x."; 306const char *VFS_DATA_FILE_BASE = "data.db2.x.";
304const char *VFS_INDEX_FILE_BASE = "index.db2.x."; 307const char *VFS_INDEX_FILE_BASE = "index.db2.x.";
305 308
306static LLString gSecondLife; 309static std::string gSecondLife;
307static LLString gWindowTitle; 310static std::string gWindowTitle;
308#ifdef LL_WINDOWS 311#ifdef LL_WINDOWS
309 static char sWindowClass[] = "Second Life"; 312 static char sWindowClass[] = "Second Life";
310#endif 313#endif
@@ -322,48 +325,6 @@ void idle_afk_check()
322 } 325 }
323} 326}
324 327
325//this function checks if the system can allocate (num_chunk)MB memory successfully.
326//if this check fails, the allocated memory is NOT freed.
327void idle_mem_check(S32 num_chunk)
328{
329 //this flag signals if memory allocation check is necessary
330 static BOOL check = TRUE ;
331
332 if(!check) //if memory check fails before, do not repeat it.
333 {
334 return ;
335 }
336 check = FALSE ; //before memory check for this frame, turn off check signal for the next frame.
337
338 S32 i = 0 ;
339 char**p = new char*[num_chunk] ;
340 if(!p)
341 {
342 return ;
343 }
344 for(i = 0 ; i < num_chunk ; i++)
345 {
346 //1MB per chunk
347 //if the allocation fails, the system should catch it.
348 p[i] = new char[1024 * 1024] ;
349
350 if(!p[i]) //in case that system try-catch is turned off
351 {
352 return ;
353 }
354 }
355
356 //release memory if the allocation check does not fail.
357 for(i = 0 ; i < num_chunk ; i++)
358 {
359 delete[] p[i] ;
360 }
361 delete[] p ;
362
363 //memory check for this frame succeeds, turn on next frame check.
364 check = TRUE ;
365}
366
367// A callback set in LLAppViewer::init() 328// A callback set in LLAppViewer::init()
368static void ui_audio_callback(const LLUUID& uuid) 329static void ui_audio_callback(const LLUUID& uuid)
369{ 330{
@@ -408,7 +369,7 @@ bool handleCrashSubmitBehaviorChanged(const LLSD& newvalue)
408 else if(gSavedSettings.getBOOL("WatchdogEnabled") == TRUE) 369 else if(gSavedSettings.getBOOL("WatchdogEnabled") == TRUE)
409 { 370 {
410 // Don't re-enable the watchdog when we change the setting; this may get called before it's started 371 // Don't re-enable the watchdog when we change the setting; this may get called before it's started
411// LLWatchdog::getInstance()->init(); 372// LLWatchdog::getInstance()->init();
412 } 373 }
413 return true; 374 return true;
414} 375}
@@ -459,6 +420,8 @@ static void settings_to_globals()
459 gMiniMapScale = gSavedSettings.getF32("MiniMapScale"); 420 gMiniMapScale = gSavedSettings.getF32("MiniMapScale");
460 gHandleKeysAsync = gSavedSettings.getBOOL("AsyncKeyboard"); 421 gHandleKeysAsync = gSavedSettings.getBOOL("AsyncKeyboard");
461 LLHoverView::sShowHoverTips = gSavedSettings.getBOOL("ShowHoverTips"); 422 LLHoverView::sShowHoverTips = gSavedSettings.getBOOL("ShowHoverTips");
423
424 LLCubeMap::sUseCubeMaps = LLFeatureManager::getInstance()->isFeatureAvailable("RenderCubeMap");
462} 425}
463 426
464static void settings_modify() 427static void settings_modify()
@@ -527,7 +490,7 @@ void LLAppViewer::initGridChoice()
527 server = llclamp(server, 0, (S32)GRID_INFO_COUNT - 1); 490 server = llclamp(server, 0, (S32)GRID_INFO_COUNT - 1);
528 if(server == GRID_INFO_OTHER) 491 if(server == GRID_INFO_OTHER)
529 { 492 {
530 LLString custom_server = gSavedSettings.getString("CustomServer"); 493 std::string custom_server = gSavedSettings.getString("CustomServer");
531 LLViewerLogin::getInstance()->setGridChoice(custom_server); 494 LLViewerLogin::getInstance()->setGridChoice(custom_server);
532 } 495 }
533 else if(server != (S32)GRID_INFO_NONE) 496 else if(server != (S32)GRID_INFO_NONE)
@@ -590,7 +553,8 @@ LLAppViewer::LLAppViewer() :
590 mQuitRequested(false), 553 mQuitRequested(false),
591 mLogoutRequestSent(false), 554 mLogoutRequestSent(false),
592 mYieldTime(-1), 555 mYieldTime(-1),
593 mMainloopTimeout(NULL) 556 mMainloopTimeout(NULL),
557 mAgentRegionLastAlive(false)
594{ 558{
595 if(NULL != sInstance) 559 if(NULL != sInstance)
596 { 560 {
@@ -656,13 +620,15 @@ bool LLAppViewer::init()
656 // *FIX: The following code isn't grouped into functions yet. 620 // *FIX: The following code isn't grouped into functions yet.
657 621
658 // 622 //
659 // Various introspection concerning the libs we're using. 623 // Various introspection concerning the libs we're using - particularly
624 // the libs involved in getting to a full login screen.
660 // 625 //
661 LL_DEBUGS("InitInfo") << "J2C Engine is: " << LLImageJ2C::getEngineInfo() << LL_ENDL; 626 LL_INFOS("InitInfo") << "J2C Engine is: " << LLImageJ2C::getEngineInfo() << LL_ENDL;
627 LL_INFOS("InitInfo") << "libcurl version is: " << LLCurl::getVersionString() << LL_ENDL;
662 628
663 // Get the single value from the crash settings file, if it exists 629 // Get the single value from the crash settings file, if it exists
664 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE); 630 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE);
665 gCrashSettings.loadFromFile(crash_settings_filename.c_str()); 631 gCrashSettings.loadFromFile(crash_settings_filename);
666 632
667 ///////////////////////////////////////////////// 633 /////////////////////////////////////////////////
668 // OS-specific login dialogs 634 // OS-specific login dialogs
@@ -702,14 +668,14 @@ bool LLAppViewer::init()
702 } 668 }
703 669
704 // Load art UUID information, don't require these strings to be declared in code. 670 // Load art UUID information, don't require these strings to be declared in code.
705 LLString colors_base_filename = gDirUtilp->findSkinnedFilename("colors_base.xml"); 671 std::string colors_base_filename = gDirUtilp->findSkinnedFilename("colors_base.xml");
706 LL_DEBUGS("InitInfo") << "Loading base colors from " << colors_base_filename << LL_ENDL; 672 LL_DEBUGS("InitInfo") << "Loading base colors from " << colors_base_filename << LL_ENDL;
707 gColors.loadFromFileLegacy(colors_base_filename.c_str(), FALSE, TYPE_COL4U); 673 gColors.loadFromFileLegacy(colors_base_filename, FALSE, TYPE_COL4U);
708 674
709 // Load overrides from user colors file 675 // Load overrides from user colors file
710 LLString user_colors_filename = gDirUtilp->findSkinnedFilename("colors.xml"); 676 std::string user_colors_filename = gDirUtilp->findSkinnedFilename("colors.xml");
711 LL_DEBUGS("InitInfo") << "Loading user colors from " << user_colors_filename << LL_ENDL; 677 LL_DEBUGS("InitInfo") << "Loading user colors from " << user_colors_filename << LL_ENDL;
712 if (gColors.loadFromFileLegacy(user_colors_filename.c_str(), FALSE, TYPE_COL4U) == 0) 678 if (gColors.loadFromFileLegacy(user_colors_filename, FALSE, TYPE_COL4U) == 0)
713 { 679 {
714 LL_DEBUGS("InitInfo") << "Cannot load user colors from " << user_colors_filename << LL_ENDL; 680 LL_DEBUGS("InitInfo") << "Cannot load user colors from " << user_colors_filename << LL_ENDL;
715 } 681 }
@@ -722,6 +688,10 @@ bool LLAppViewer::init()
722 &LLUI::sGLScaleFactor); 688 &LLUI::sGLScaleFactor);
723 689
724 LLWeb::initClass(); // do this after LLUI 690 LLWeb::initClass(); // do this after LLUI
691 LLTextEditor::setURLCallbacks(&LLWeb::loadURL,
692 &LLURLDispatcher::dispatchFromTextEditor,
693 &LLURLDispatcher::dispatchFromTextEditor);
694
725 LLUICtrlFactory::getInstance()->setupPaths(); // update paths with correct language set 695 LLUICtrlFactory::getInstance()->setupPaths(); // update paths with correct language set
726 696
727 ///////////////////////////////////////////////// 697 /////////////////////////////////////////////////
@@ -736,7 +706,7 @@ bool LLAppViewer::init()
736 LLViewerJointMesh::updateVectorize(); 706 LLViewerJointMesh::updateVectorize();
737 707
738 // load MIME type -> media impl mappings 708 // load MIME type -> media impl mappings
739 LLMIMETypes::parseMIMETypes( "mime_types.xml" ); 709 LLMIMETypes::parseMIMETypes( std::string("mime_types.xml") );
740 710
741 711
742 // Copy settings to globals. *TODO: Remove or move to appropriage class initializers 712 // Copy settings to globals. *TODO: Remove or move to appropriage class initializers
@@ -783,8 +753,8 @@ bool LLAppViewer::init()
783 "If it continues to persist, you may need to completely uninstall " << 753 "If it continues to persist, you may need to completely uninstall " <<
784 gSecondLife << " and reinstall it."; 754 gSecondLife << " and reinstall it.";
785 OSMessageBox( 755 OSMessageBox(
786 msg.str().c_str(), 756 msg.str(),
787 NULL, 757 LLStringUtil::null,
788 OSMB_OK); 758 OSMB_OK);
789 return 1; 759 return 1;
790 } 760 }
@@ -794,12 +764,12 @@ bool LLAppViewer::init()
794 // 764 //
795 initWindow(); 765 initWindow();
796 766
797 #if LL_WINDOWS && LL_LCD_COMPILE 767#if LL_LCD_COMPILE
798 // start up an LCD window on a logitech keyboard, if there is one 768 // start up an LCD window on a logitech keyboard, if there is one
799 HINSTANCE hInstance = GetModuleHandle(NULL); 769 HINSTANCE hInstance = GetModuleHandle(NULL);
800 gLcdScreen = new LLLCD(hInstance); 770 gLcdScreen = new LLLCD(hInstance);
801 CreateLCDDebugWindows(); 771 CreateLCDDebugWindows();
802 #endif 772#endif
803 773
804 gGLManager.getGLInfo(gDebugInfo); 774 gGLManager.getGLInfo(gDebugInfo);
805 gGLManager.printGLInfoString(); 775 gGLManager.printGLInfoString();
@@ -808,12 +778,12 @@ bool LLAppViewer::init()
808 bind_keyboard_functions(); 778 bind_keyboard_functions();
809 779
810 // Load Default bindings 780 // Load Default bindings
811 if (!gViewerKeyboard.loadBindings(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"keys.ini").c_str())) 781 if (!gViewerKeyboard.loadBindings(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"keys.ini")))
812 { 782 {
813 LL_ERRS("InitInfo") << "Unable to open keys.ini" << LL_ENDL; 783 LL_ERRS("InitInfo") << "Unable to open keys.ini" << LL_ENDL;
814 } 784 }
815 // Load Custom bindings (override defaults) 785 // Load Custom bindings (override defaults)
816 gViewerKeyboard.loadBindings(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"custom_keys.ini").c_str()); 786 gViewerKeyboard.loadBindings(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"custom_keys.ini"));
817 787
818 // If we don't have the right GL requirements, exit. 788 // If we don't have the right GL requirements, exit.
819 if (!gGLManager.mHasRequirements && !gNoRender) 789 if (!gGLManager.mHasRequirements && !gNoRender)
@@ -821,16 +791,16 @@ bool LLAppViewer::init()
821 // can't use an alert here since we're existing and 791 // can't use an alert here since we're existing and
822 // all hell breaks lose. 792 // all hell breaks lose.
823 OSMessageBox( 793 OSMessageBox(
824 LLAlertDialog::getTemplateMessage("UnsupportedGLRequirements").c_str(), 794 LLAlertDialog::getTemplateMessage("UnsupportedGLRequirements"),
825 NULL, 795 LLStringUtil::null,
826 OSMB_OK); 796 OSMB_OK);
827 return 0; 797 return 0;
828 } 798 }
829 799
830 800
831 bool unsupported = false; 801 bool unsupported = false;
832 LLString::format_map_t args; 802 LLStringUtil::format_map_t args;
833 LLString minSpecs; 803 std::string minSpecs;
834 804
835 // get cpu data from xml 805 // get cpu data from xml
836 std::stringstream minCPUString(LLAlertDialog::getTemplateMessage("UnsupportedCPUAmount")); 806 std::stringstream minCPUString(LLAlertDialog::getTemplateMessage("UnsupportedCPUAmount"));
@@ -891,6 +861,9 @@ bool LLAppViewer::init()
891 861
892bool LLAppViewer::mainLoop() 862bool LLAppViewer::mainLoop()
893{ 863{
864 mMainloopTimeout = new LLWatchdogTimeout();
865 // *FIX:Mani - Make this a setting, once new settings exist in this branch.
866
894 //------------------------------------------- 867 //-------------------------------------------
895 // Run main loop until time to quit 868 // Run main loop until time to quit
896 //------------------------------------------- 869 //-------------------------------------------
@@ -939,10 +912,13 @@ bool LLAppViewer::mainLoop()
939 { 912 {
940 debugTime.reset(); 913 debugTime.reset();
941 } 914 }
915
942#endif 916#endif
943 917 //memory leaking simulation
944 //at the beginning of every frame, check if the system can successfully allocate 10 * 1 MB memory. 918 if(LLFloaterMemLeak::getInstance())
945 idle_mem_check(10) ; 919 {
920 LLFloaterMemLeak::getInstance()->idle() ;
921 }
946 922
947 if (!LLApp::isExiting()) 923 if (!LLApp::isExiting())
948 { 924 {
@@ -962,20 +938,23 @@ bool LLAppViewer::mainLoop()
962 gKeyboard->scanKeyboard(); 938 gKeyboard->scanKeyboard();
963 } 939 }
964 940
965 pingMainloopTimeout("Main:Messages");
966
967 // Update state based on messages, user input, object idle. 941 // Update state based on messages, user input, object idle.
968 { 942 {
943 pauseMainloopTimeout(); // *TODO: Remove. Messages shouldn't be stalling for 20+ seconds!
944
969 LLFastTimer t3(LLFastTimer::FTM_IDLE); 945 LLFastTimer t3(LLFastTimer::FTM_IDLE);
970 idle(); 946 idle();
971 947
972 { 948 {
949 pingMainloopTimeout("Main:ServicePump");
973 LLFastTimer t4(LLFastTimer::FTM_PUMP); 950 LLFastTimer t4(LLFastTimer::FTM_PUMP);
974 gAres->process(); 951 gAres->process();
975 // this pump is necessary to make the login screen show up 952 // this pump is necessary to make the login screen show up
976 gServicePump->pump(); 953 gServicePump->pump();
977 gServicePump->callback(); 954 gServicePump->callback();
978 } 955 }
956
957 resumeMainloopTimeout();
979 } 958 }
980 959
981 if (gDoDisconnect && (LLStartUp::getStartupState() == STATE_STARTED)) 960 if (gDoDisconnect && (LLStartUp::getStartupState() == STATE_STARTED))
@@ -995,7 +974,7 @@ bool LLAppViewer::mainLoop()
995 pingMainloopTimeout("Main:Snapshot"); 974 pingMainloopTimeout("Main:Snapshot");
996 LLFloaterSnapshot::update(); // take snapshots 975 LLFloaterSnapshot::update(); // take snapshots
997 976
998#if LL_WINDOWS && LL_LCD_COMPILE 977#if LL_LCD_COMPILE
999 // update LCD Screen 978 // update LCD Screen
1000 pingMainloopTimeout("Main:LCD"); 979 pingMainloopTimeout("Main:LCD");
1001 gLcdScreen->UpdateDisplay(); 980 gLcdScreen->UpdateDisplay();
@@ -1077,6 +1056,11 @@ bool LLAppViewer::mainLoop()
1077 break; 1056 break;
1078 } 1057 }
1079 } 1058 }
1059 if ((LLStartUp::getStartupState() >= STATE_CLEANUP) &&
1060 (frameTimer.getElapsedTimeF64() > FRAME_STALL_THRESHOLD))
1061 {
1062 gFrameStalls++;
1063 }
1080 frameTimer.reset(); 1064 frameTimer.reset();
1081 1065
1082 // Prevent the worker threads from running while rendering. 1066 // Prevent the worker threads from running while rendering.
@@ -1099,6 +1083,12 @@ bool LLAppViewer::mainLoop()
1099 catch(std::bad_alloc) 1083 catch(std::bad_alloc)
1100 { 1084 {
1101 llwarns << "Bad memory allocation in LLAppViewer::mainLoop()!" << llendl ; 1085 llwarns << "Bad memory allocation in LLAppViewer::mainLoop()!" << llendl ;
1086
1087 //stop memory leaking simulation
1088 if(LLFloaterMemLeak::getInstance())
1089 {
1090 LLFloaterMemLeak::getInstance()->stop() ;
1091 }
1102 } 1092 }
1103 } 1093 }
1104 1094
@@ -1112,6 +1102,12 @@ bool LLAppViewer::mainLoop()
1112 catch(std::bad_alloc) 1102 catch(std::bad_alloc)
1113 { 1103 {
1114 llwarns << "Bad memory allocation when saveFinalSnapshot() is called!" << llendl ; 1104 llwarns << "Bad memory allocation when saveFinalSnapshot() is called!" << llendl ;
1105
1106 //stop memory leaking simulation
1107 if(LLFloaterMemLeak::getInstance())
1108 {
1109 LLFloaterMemLeak::getInstance()->stop() ;
1110 }
1115 } 1111 }
1116 } 1112 }
1117 1113
@@ -1227,8 +1223,18 @@ bool LLAppViewer::cleanup()
1227 ms_sleep(100); 1223 ms_sleep(100);
1228 } 1224 }
1229 llinfos << "Shutting down." << llendflush; 1225 llinfos << "Shutting down." << llendflush;
1226
1227 // Destroy the UI
1228 gViewerWindow->shutdownViews();
1229
1230 // Clean up selection managers after UI is destroyed, as UI may be observing them.
1231 // Clean up before GL is shut down because we might be holding on to objects with texture references
1232 LLSelectMgr::cleanupGlobals();
1233
1234 // Shut down OpenGL
1235 gViewerWindow->shutdownGL();
1230 1236
1231 // Destroy Windows(R) window, and make sure we're not fullscreen 1237 // Destroy window, and make sure we're not fullscreen
1232 // This may generate window reshape and activation events. 1238 // This may generate window reshape and activation events.
1233 // Therefore must do this before destroying the message system. 1239 // Therefore must do this before destroying the message system.
1234 delete gViewerWindow; 1240 delete gViewerWindow;
@@ -1239,10 +1245,6 @@ bool LLAppViewer::cleanup()
1239 delete gKeyboard; 1245 delete gKeyboard;
1240 gKeyboard = NULL; 1246 gKeyboard = NULL;
1241 1247
1242 // Clean up selection managers after UI is destroyed, as UI
1243 // may be observing them.
1244 LLSelectMgr::cleanupGlobals();
1245
1246 LLViewerObject::cleanupVOClasses(); 1248 LLViewerObject::cleanupVOClasses();
1247 1249
1248 LLWaterParamManager::cleanupClass(); 1250 LLWaterParamManager::cleanupClass();
@@ -1258,7 +1260,7 @@ bool LLAppViewer::cleanup()
1258 // gDXHardware.cleanup(); 1260 // gDXHardware.cleanup();
1259 //#endif // LL_WINDOWS 1261 //#endif // LL_WINDOWS
1260 1262
1261#if LL_WINDOWS && LL_LCD_COMPILE 1263#if LL_LCD_COMPILE
1262 // shut down the LCD window on a logitech keyboard, if there is one 1264 // shut down the LCD window on a logitech keyboard, if there is one
1263 delete gLcdScreen; 1265 delete gLcdScreen;
1264 gLcdScreen = NULL; 1266 gLcdScreen = NULL;
@@ -1287,6 +1289,7 @@ bool LLAppViewer::cleanup()
1287 // Shut down the VFS's AFTER the decode manager cleans up (since it cleans up vfiles). 1289 // Shut down the VFS's AFTER the decode manager cleans up (since it cleans up vfiles).
1288 // Also after viewerwindow is deleted, since it may have image pointers (which have vfiles) 1290 // Also after viewerwindow is deleted, since it may have image pointers (which have vfiles)
1289 // Also after shutting down the messaging system since it has VFS dependencies 1291 // Also after shutting down the messaging system since it has VFS dependencies
1292
1290 // 1293 //
1291 LLVFile::cleanupClass(); 1294 LLVFile::cleanupClass();
1292 llinfos << "VFS cleaned up" << llendflush; 1295 llinfos << "VFS cleaned up" << llendflush;
@@ -1305,7 +1308,7 @@ bool LLAppViewer::cleanup()
1305 1308
1306 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE); 1309 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE);
1307 // save all settings, even if equals defaults 1310 // save all settings, even if equals defaults
1308 gCrashSettings.saveToFile(crash_settings_filename.c_str(), FALSE); 1311 gCrashSettings.saveToFile(crash_settings_filename, FALSE);
1309 1312
1310 gSavedSettings.cleanup(); 1313 gSavedSettings.cleanup();
1311 gColors.cleanup(); 1314 gColors.cleanup();
@@ -1320,9 +1323,8 @@ bool LLAppViewer::cleanup()
1320 if (mPurgeOnExit) 1323 if (mPurgeOnExit)
1321 { 1324 {
1322 llinfos << "Purging all cache files on exit" << llendflush; 1325 llinfos << "Purging all cache files on exit" << llendflush;
1323 char mask[LL_MAX_PATH]; /* Flawfinder: ignore */ 1326 std::string mask = gDirUtilp->getDirDelimiter() + "*.*";
1324 snprintf(mask, LL_MAX_PATH, "%s*.*", gDirUtilp->getDirDelimiter().c_str()); /* Flawfinder: ignore */ 1327 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""),mask);
1325 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"").c_str(),mask);
1326 } 1328 }
1327 1329
1328 removeMarkerFile(); // Any crashes from here on we'll just have to ignore 1330 removeMarkerFile(); // Any crashes from here on we'll just have to ignore
@@ -1443,7 +1445,7 @@ bool LLAppViewer::initThreads()
1443void errorCallback(const std::string &error_string) 1445void errorCallback(const std::string &error_string)
1444{ 1446{
1445#ifndef LL_RELEASE_FOR_DOWNLOAD 1447#ifndef LL_RELEASE_FOR_DOWNLOAD
1446 OSMessageBox(error_string.c_str(), "Fatal Error", OSMB_OK); 1448 OSMessageBox(error_string, "Fatal Error", OSMB_OK);
1447#endif 1449#endif
1448 1450
1449 //Set the ErrorActivated global so we know to create a marker file 1451 //Set the ErrorActivated global so we know to create a marker file
@@ -1464,12 +1466,12 @@ bool LLAppViewer::initLogging()
1464 // Remove the last ".old" log file. 1466 // Remove the last ".old" log file.
1465 std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, 1467 std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,
1466 "SecondLife.old"); 1468 "SecondLife.old");
1467 LLFile::remove(old_log_file.c_str()); 1469 LLFile::remove(old_log_file);
1468 1470
1469 // Rename current log file to ".old" 1471 // Rename current log file to ".old"
1470 std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, 1472 std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,
1471 "SecondLife.log"); 1473 "SecondLife.log");
1472 LLFile::rename(log_file.c_str(), old_log_file.c_str()); 1474 LLFile::rename(log_file, old_log_file);
1473 1475
1474 // Set the log file to SecondLife.log 1476 // Set the log file to SecondLife.log
1475 1477
@@ -1483,10 +1485,10 @@ void LLAppViewer::loadSettingsFromDirectory(ELLPath path_index, bool set_default
1483{ 1485{
1484 for(LLSD::map_iterator itr = mSettingsFileList.beginMap(); itr != mSettingsFileList.endMap(); ++itr) 1486 for(LLSD::map_iterator itr = mSettingsFileList.beginMap(); itr != mSettingsFileList.endMap(); ++itr)
1485 { 1487 {
1486 LLString settings_name = (*itr).first; 1488 std::string settings_name = (*itr).first;
1487 LLString settings_file = mSettingsFileList[settings_name].asString(); 1489 std::string settings_file = mSettingsFileList[settings_name].asString();
1488 1490
1489 LLString full_settings_path = gDirUtilp->getExpandedFilename(path_index, settings_file); 1491 std::string full_settings_path = gDirUtilp->getExpandedFilename(path_index, settings_file);
1490 1492
1491 if(settings_name == sGlobalSettingsName 1493 if(settings_name == sGlobalSettingsName
1492 && path_index == LL_PATH_USER_SETTINGS) 1494 && path_index == LL_PATH_USER_SETTINGS)
@@ -1658,8 +1660,8 @@ bool LLAppViewer::initConfiguration()
1658 << "Error: " << clp.getErrorMessage(); 1660 << "Error: " << clp.getErrorMessage();
1659 1661
1660 OSMessageBox( 1662 OSMessageBox(
1661 msg.str().c_str(), 1663 msg.str(),
1662 NULL, 1664 LLStringUtil::null,
1663 OSMB_OK); 1665 OSMB_OK);
1664 1666
1665 return false; 1667 return false;
@@ -1827,7 +1829,7 @@ bool LLAppViewer::initConfiguration()
1827 } 1829 }
1828 1830
1829 const LLControlVariable* skinfolder = gSavedSettings.getControl("SkinCurrent"); 1831 const LLControlVariable* skinfolder = gSavedSettings.getControl("SkinCurrent");
1830 if(skinfolder && LLString::null != skinfolder->getValue().asString()) 1832 if(skinfolder && LLStringUtil::null != skinfolder->getValue().asString())
1831 { 1833 {
1832 gDirUtilp->setSkinFolder(skinfolder->getValue().asString()); 1834 gDirUtilp->setSkinFolder(skinfolder->getValue().asString());
1833 } 1835 }
@@ -1878,8 +1880,8 @@ bool LLAppViewer::initConfiguration()
1878 std::ostringstream msg; 1880 std::ostringstream msg;
1879 msg << gSecondLife << " requires a processor with AltiVec (G4 or later)."; 1881 msg << gSecondLife << " requires a processor with AltiVec (G4 or later).";
1880 OSMessageBox( 1882 OSMessageBox(
1881 msg.str().c_str(), 1883 msg.str(),
1882 NULL, 1884 LLStringUtil::null,
1883 OSMB_OK); 1885 OSMB_OK);
1884 removeMarkerFile(); 1886 removeMarkerFile();
1885 return false; 1887 return false;
@@ -1893,14 +1895,14 @@ bool LLAppViewer::initConfiguration()
1893 std::ostringstream splash_msg; 1895 std::ostringstream splash_msg;
1894 splash_msg << "Loading " << gSecondLife << "..."; 1896 splash_msg << "Loading " << gSecondLife << "...";
1895 LLSplashScreen::show(); 1897 LLSplashScreen::show();
1896 LLSplashScreen::update(splash_msg.str().c_str()); 1898 LLSplashScreen::update(splash_msg.str());
1897 1899
1898 //LLVolumeMgr::initClass(); 1900 //LLVolumeMgr::initClass();
1899 LLVolumeMgr* volume_manager = new LLVolumeMgr(); 1901 LLVolumeMgr* volume_manager = new LLVolumeMgr();
1900 volume_manager->useMutex(); // LLApp and LLMutex magic must be manually enabled 1902 volume_manager->useMutex(); // LLApp and LLMutex magic must be manually enabled
1901 LLPrimitive::setVolumeManager(volume_manager); 1903 LLPrimitive::setVolumeManager(volume_manager);
1902 1904
1903 // Note: this is where we used to initialize LLFeatureManager::getInstance()->. 1905 // Note: this is where we used to initialize gFeatureManagerp.
1904 1906
1905 gStartTime = totalTime(); 1907 gStartTime = totalTime();
1906 1908
@@ -1910,11 +1912,11 @@ bool LLAppViewer::initConfiguration()
1910#if LL_RELEASE_FOR_DOWNLOAD 1912#if LL_RELEASE_FOR_DOWNLOAD
1911 gWindowTitle = gSecondLife; 1913 gWindowTitle = gSecondLife;
1912#elif LL_DEBUG 1914#elif LL_DEBUG
1913 gWindowTitle = gSecondLife + LLString(" [DEBUG] ") + gArgs; 1915 gWindowTitle = gSecondLife + std::string(" [DEBUG] ") + gArgs;
1914#else 1916#else
1915 gWindowTitle = gSecondLife + LLString(" ") + gArgs; 1917 gWindowTitle = gSecondLife + std::string(" ") + gArgs;
1916#endif 1918#endif
1917 LLString::truncate(gWindowTitle, 255); 1919 LLStringUtil::truncate(gWindowTitle, 255);
1918 1920
1919 //RN: if we received a URL, hand it off to the existing instance 1921 //RN: if we received a URL, hand it off to the existing instance
1920 // don't call anotherInstanceRunning() when doing URL handoff, as 1922 // don't call anotherInstanceRunning() when doing URL handoff, as
@@ -1955,8 +1957,8 @@ bool LLAppViewer::initConfiguration()
1955 "Check your task bar for a minimized copy of the program.\n" 1957 "Check your task bar for a minimized copy of the program.\n"
1956 "If this message persists, restart your computer.", 1958 "If this message persists, restart your computer.",
1957 OSMessageBox( 1959 OSMessageBox(
1958 msg.str().c_str(), 1960 msg.str(),
1959 NULL, 1961 LLStringUtil::null,
1960 OSMB_OK); 1962 OSMB_OK);
1961 return false; 1963 return false;
1962 } 1964 }
@@ -1977,9 +1979,9 @@ bool LLAppViewer::initConfiguration()
1977 std::string alert; 1979 std::string alert;
1978 alert = gSecondLife; 1980 alert = gSecondLife;
1979 alert += " Alert"; 1981 alert += " Alert";
1980 S32 choice = OSMessageBox(msg.str().c_str(), 1982 S32 choice = OSMessageBox(msg.str(),
1981 alert.c_str(), 1983 alert,
1982 OSMB_YESNO); 1984 OSMB_YESNO);
1983 if (OSBTN_YES == choice) 1985 if (OSBTN_YES == choice)
1984 { 1986 {
1985 llinfos << "Sending crash report." << llendl; 1987 llinfos << "Sending crash report." << llendl;
@@ -1995,7 +1997,7 @@ bool LLAppViewer::initConfiguration()
1995 _spawnl(_P_WAIT, exe_path.c_str(), exe_path.c_str(), arg_string.c_str(), NULL); 1997 _spawnl(_P_WAIT, exe_path.c_str(), exe_path.c_str(), arg_string.c_str(), NULL);
1996#elif LL_DARWIN 1998#elif LL_DARWIN
1997 std::string command_str; 1999 std::string command_str;
1998 command_str = "crashreporter.app/Contents/MacOS/crashreporter "; 2000 command_str = "mac-crash-logger.app/Contents/MacOS/mac-crash-logger ";
1999 command_str += "-previous"; 2001 command_str += "-previous";
2000 // XXX -- We need to exit fullscreen mode for this to work. 2002 // XXX -- We need to exit fullscreen mode for this to work.
2001 // XXX -- system() also doesn't wait for completion. Hmm... 2003 // XXX -- system() also doesn't wait for completion. Hmm...
@@ -2007,11 +2009,12 @@ bool LLAppViewer::initConfiguration()
2007 cmd += "linux-crash-logger.bin"; 2009 cmd += "linux-crash-logger.bin";
2008#else // LL_SOLARIS 2010#else // LL_SOLARIS
2009 cmd += "bin/solaris-crash-logger"; 2011 cmd += "bin/solaris-crash-logger";
2010#endif 2012#endif // LL_LINUX
2011 char* const cmdargv[] = 2013 char* const cmdargv[] =
2012 {(char*)cmd.c_str(), 2014 {(char*)cmd.c_str(),
2013 (char*)"-previous", 2015 (char*)"-previous",
2014 NULL}; 2016 NULL};
2017 fflush(NULL); // flush all buffers before the child inherits them
2015 pid_t pid = fork(); 2018 pid_t pid = fork();
2016 if (pid == 0) 2019 if (pid == 0)
2017 { // child 2020 { // child
@@ -2057,10 +2060,10 @@ bool LLAppViewer::initConfiguration()
2057 } 2060 }
2058 2061
2059 // need to do this here - need to have initialized global settings first 2062 // need to do this here - need to have initialized global settings first
2060 LLString nextLoginLocation = gSavedSettings.getString( "NextLoginLocation" ); 2063 std::string nextLoginLocation = gSavedSettings.getString( "NextLoginLocation" );
2061 if ( nextLoginLocation.length() ) 2064 if ( nextLoginLocation.length() )
2062 { 2065 {
2063 LLURLSimString::setString( nextLoginLocation.c_str() ); 2066 LLURLSimString::setString( nextLoginLocation );
2064 }; 2067 };
2065 2068
2066 gLastRunVersion = gSavedSettings.getString("LastRunVersion"); 2069 gLastRunVersion = gSavedSettings.getString("LastRunVersion");
@@ -2078,14 +2081,9 @@ bool LLAppViewer::initWindow()
2078 // Hide the splash screen 2081 // Hide the splash screen
2079 LLSplashScreen::hide(); 2082 LLSplashScreen::hide();
2080 2083
2081 // HACK: Need a non-const char * for stupid window name (propagated deep down)
2082 char window_title_str[256]; /* Flawfinder: ignore */
2083 strncpy(window_title_str, gWindowTitle.c_str(), sizeof(window_title_str) - 1); /* Flawfinder: ignore */
2084 window_title_str[sizeof(window_title_str) - 1] = '\0';
2085
2086 // always start windowed 2084 // always start windowed
2087 BOOL ignorePixelDepth = gSavedSettings.getBOOL("IgnorePixelDepth"); 2085 BOOL ignorePixelDepth = gSavedSettings.getBOOL("IgnorePixelDepth");
2088 gViewerWindow = new LLViewerWindow(window_title_str, "Second Life", 2086 gViewerWindow = new LLViewerWindow(gWindowTitle, "Second Life",
2089 gSavedSettings.getS32("WindowX"), gSavedSettings.getS32("WindowY"), 2087 gSavedSettings.getS32("WindowX"), gSavedSettings.getS32("WindowY"),
2090 gSavedSettings.getS32("WindowWidth"), gSavedSettings.getS32("WindowHeight"), 2088 gSavedSettings.getS32("WindowWidth"), gSavedSettings.getS32("WindowHeight"),
2091 FALSE, ignorePixelDepth); 2089 FALSE, ignorePixelDepth);
@@ -2149,7 +2147,7 @@ void LLAppViewer::writeDebugInfo()
2149{ 2147{
2150 std::string debug_filename = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"debug_info.log"); 2148 std::string debug_filename = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"debug_info.log");
2151 llinfos << "Opening debug file " << debug_filename << llendl; 2149 llinfos << "Opening debug file " << debug_filename << llendl;
2152 std::ofstream out_file(debug_filename.c_str()); 2150 llofstream out_file(debug_filename);
2153 LLSDSerialize::toPrettyXML(gDebugInfo, out_file); 2151 LLSDSerialize::toPrettyXML(gDebugInfo, out_file);
2154 out_file.close(); 2152 out_file.close();
2155} 2153}
@@ -2208,11 +2206,10 @@ void LLAppViewer::cleanupSavedSettings()
2208 } 2206 }
2209} 2207}
2210 2208
2211void LLAppViewer::removeCacheFiles(const char* file_mask) 2209void LLAppViewer::removeCacheFiles(const std::string& file_mask)
2212{ 2210{
2213 char mask[LL_MAX_PATH]; /* Flawfinder: ignore */ 2211 std::string mask = gDirUtilp->getDirDelimiter() + file_mask;
2214 snprintf(mask, LL_MAX_PATH, "%s%s", gDirUtilp->getDirDelimiter().c_str(), file_mask); /* Flawfinder: ignore */ 2212 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), mask);
2215 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "").c_str(), mask);
2216} 2213}
2217 2214
2218void LLAppViewer::writeSystemInfo() 2215void LLAppViewer::writeSystemInfo()
@@ -2237,7 +2234,7 @@ void LLAppViewer::writeSystemInfo()
2237 gDebugInfo["RAMInfo"]["Physical"] = (LLSD::Integer)(gSysMemory.getPhysicalMemoryKB()); 2234 gDebugInfo["RAMInfo"]["Physical"] = (LLSD::Integer)(gSysMemory.getPhysicalMemoryKB());
2238 gDebugInfo["RAMInfo"]["Allocated"] = (LLSD::Integer)(gMemoryAllocated>>10); // MB -> KB 2235 gDebugInfo["RAMInfo"]["Allocated"] = (LLSD::Integer)(gMemoryAllocated>>10); // MB -> KB
2239 gDebugInfo["OSInfo"] = getOSInfo().getOSStringSimple(); 2236 gDebugInfo["OSInfo"] = getOSInfo().getOSStringSimple();
2240 2237
2241 // The user is not logged on yet, but record the current grid choice login url 2238 // The user is not logged on yet, but record the current grid choice login url
2242 // which may have been the intended grid. This can b 2239 // which may have been the intended grid. This can b
2243 gDebugInfo["GridName"] = LLViewerLogin::getInstance()->getGridLabel(); 2240 gDebugInfo["GridName"] = LLViewerLogin::getInstance()->getGridLabel();
@@ -2320,8 +2317,8 @@ void LLAppViewer::handleViewerCrash()
2320 2317
2321 gDebugInfo["SettingsFilename"] = gSavedSettings.getString("ClientSettingsFile"); 2318 gDebugInfo["SettingsFilename"] = gSavedSettings.getString("ClientSettingsFile");
2322 gDebugInfo["CAFilename"] = gDirUtilp->getCAFile(); 2319 gDebugInfo["CAFilename"] = gDirUtilp->getCAFile();
2323 gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName().c_str(); 2320 gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName();
2324 gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath().c_str(); 2321 gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath();
2325 if(gLogoutInProgress) 2322 if(gLogoutInProgress)
2326 { 2323 {
2327 gDebugInfo["LastExecEvent"] = LAST_EXEC_LOGOUT_CRASH; 2324 gDebugInfo["LastExecEvent"] = LAST_EXEC_LOGOUT_CRASH;
@@ -2348,7 +2345,7 @@ void LLAppViewer::handleViewerCrash()
2348 //we're already in a crash situation 2345 //we're already in a crash situation
2349 if (gDirUtilp) 2346 if (gDirUtilp)
2350 { 2347 {
2351 LLString crash_file_name; 2348 std::string crash_file_name;
2352 if(gLLErrorActivated) crash_file_name = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,LLERROR_MARKER_FILE_NAME); 2349 if(gLLErrorActivated) crash_file_name = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,LLERROR_MARKER_FILE_NAME);
2353 else crash_file_name = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,ERROR_MARKER_FILE_NAME); 2350 else crash_file_name = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,ERROR_MARKER_FILE_NAME);
2354 llinfos << "Creating crash marker file " << crash_file_name << llendl; 2351 llinfos << "Creating crash marker file " << crash_file_name << llendl;
@@ -2368,7 +2365,7 @@ void LLAppViewer::handleViewerCrash()
2368 { 2365 {
2369 std::string filename; 2366 std::string filename;
2370 filename = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "stats.log"); 2367 filename = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "stats.log");
2371 llofstream file(filename.c_str(), llofstream::binary); 2368 llofstream file(filename, llofstream::binary);
2372 if(file.good()) 2369 if(file.good())
2373 { 2370 {
2374 llinfos << "Handle viewer crash generating stats log." << llendl; 2371 llinfos << "Handle viewer crash generating stats log." << llendl;
@@ -2457,9 +2454,9 @@ void LLAppViewer::initMarkerFile()
2457 // These checks should also remove these files for the last 2 cases if they currently exist 2454 // These checks should also remove these files for the last 2 cases if they currently exist
2458 2455
2459 //LLError/Error checks. Only one of these should ever happen at a time. 2456 //LLError/Error checks. Only one of these should ever happen at a time.
2460 LLString logout_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LOGOUT_MARKER_FILE_NAME); 2457 std::string logout_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LOGOUT_MARKER_FILE_NAME);
2461 LLString llerror_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LLERROR_MARKER_FILE_NAME); 2458 std::string llerror_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LLERROR_MARKER_FILE_NAME);
2462 LLString error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME); 2459 std::string error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME);
2463 2460
2464 apr_file_t* fMarker = ll_apr_file_open(logout_marker_file, LL_APR_RB); 2461 apr_file_t* fMarker = ll_apr_file_open(logout_marker_file, LL_APR_RB);
2465 if(fMarker != NULL) 2462 if(fMarker != NULL)
@@ -2594,11 +2591,11 @@ static void finish_early_exit(S32 option, void* userdata)
2594 LLAppViewer::instance()->forceQuit(); 2591 LLAppViewer::instance()->forceQuit();
2595} 2592}
2596 2593
2597void LLAppViewer::earlyExit(const LLString& msg) 2594void LLAppViewer::earlyExit(const std::string& msg)
2598{ 2595{
2599 llwarns << "app_early_exit: " << msg << llendl; 2596 llwarns << "app_early_exit: " << msg << llendl;
2600 gDoDisconnect = TRUE; 2597 gDoDisconnect = TRUE;
2601// LLStringBase<char>::format_map_t args; 2598// LLStringUtil::format_map_t args;
2602// args["[MESSAGE]"] = mesg; 2599// args["[MESSAGE]"] = mesg;
2603// gViewerWindow->alertXml("AppEarlyExit", args, finish_early_exit); 2600// gViewerWindow->alertXml("AppEarlyExit", args, finish_early_exit);
2604 LLAlertDialog::showCritical(msg, finish_early_exit, NULL); 2601 LLAlertDialog::showCritical(msg, finish_early_exit, NULL);
@@ -2639,9 +2636,41 @@ bool LLAppViewer::initCache()
2639 } 2636 }
2640 } 2637 }
2641 2638
2639 // Delete old cache directory
2640#ifdef LL_DARWIN
2641 if (LL_VERSION_MAJOR >= 1 && LL_VERSION_MINOR >= 21)
2642 {
2643 if (gLastRunVersion != gCurrentVersion)
2644 {
2645 // NOTE: (Nyx) as of 1.21, cache for mac is moving to /library/caches/SecondLife from
2646 // /library/application support/SecondLife/cache This should clear/delete the old dir.
2647 std::string cache_dir = gDirUtilp->getOSUserAppDir();
2648 std::string new_cache_dir = gDirUtilp->getOSCacheDir();
2649 cache_dir = cache_dir + "/cache";
2650 new_cache_dir = new_cache_dir + "/" + gSecondLife;
2651 if (gDirUtilp->fileExists(cache_dir))
2652 {
2653 gDirUtilp->setCacheDir(cache_dir);
2654 purgeCache();
2655 gDirUtilp->setCacheDir(new_cache_dir);
2656
2657 std::string ds_store = cache_dir + "/.DS_Store";
2658 if (gDirUtilp->fileExists(ds_store.c_str()))
2659 {
2660 LLFile::remove(ds_store.c_str());
2661 }
2662 if (LLFile::remove(cache_dir.c_str()) != 0)
2663 {
2664 llwarns << "could not delete old cache directory" << llendl;
2665 }
2666 }
2667 }
2668 }
2669#endif
2670
2642 // Setup and verify the cache location 2671 // Setup and verify the cache location
2643 LLString cache_location = gSavedSettings.getString("CacheLocation"); 2672 std::string cache_location = gSavedSettings.getString("CacheLocation");
2644 LLString new_cache_location = gSavedSettings.getString("NewCacheLocation"); 2673 std::string new_cache_location = gSavedSettings.getString("NewCacheLocation");
2645 if (new_cache_location != cache_location) 2674 if (new_cache_location != cache_location)
2646 { 2675 {
2647 gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation")); 2676 gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation"));
@@ -2695,12 +2724,12 @@ bool LLAppViewer::initCache()
2695 srand(time(NULL)); // Flawfinder: ignore 2724 srand(time(NULL)); // Flawfinder: ignore
2696 U32 old_salt = gSavedSettings.getU32("VFSSalt"); 2725 U32 old_salt = gSavedSettings.getU32("VFSSalt");
2697 U32 new_salt; 2726 U32 new_salt;
2698 char old_vfs_data_file[LL_MAX_PATH]; // Flawfinder: ignore 2727 std::string old_vfs_data_file;
2699 char old_vfs_index_file[LL_MAX_PATH]; // Flawfinder: ignore 2728 std::string old_vfs_index_file;
2700 char new_vfs_data_file[LL_MAX_PATH]; // Flawfinder: ignore 2729 std::string new_vfs_data_file;
2701 char new_vfs_index_file[LL_MAX_PATH]; // Flawfinder: ignore 2730 std::string new_vfs_index_file;
2702 char static_vfs_index_file[LL_MAX_PATH]; // Flawfinder: ignore 2731 std::string static_vfs_index_file;
2703 char static_vfs_data_file[LL_MAX_PATH]; // Flawfinder: ignore 2732 std::string static_vfs_data_file;
2704 2733
2705 if (gSavedSettings.getBOOL("AllowMultipleViewers")) 2734 if (gSavedSettings.getBOOL("AllowMultipleViewers"))
2706 { 2735 {
@@ -2715,9 +2744,7 @@ bool LLAppViewer::initCache()
2715 } while( new_salt == old_salt ); 2744 } while( new_salt == old_salt );
2716 } 2745 }
2717 2746
2718 snprintf(old_vfs_data_file, LL_MAX_PATH, "%s%u", // Flawfinder: ignore 2747 old_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE) + llformat("%u",old_salt);
2719 gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE).c_str(),
2720 old_salt);
2721 2748
2722 // make sure this file exists 2749 // make sure this file exists
2723 llstat s; 2750 llstat s;
@@ -2736,29 +2763,18 @@ bool LLAppViewer::initCache()
2736 std::string found_file; 2763 std::string found_file;
2737 if (gDirUtilp->getNextFileInDir(dir, mask, found_file, false)) 2764 if (gDirUtilp->getNextFileInDir(dir, mask, found_file, false))
2738 { 2765 {
2739 snprintf(old_vfs_data_file, LL_MAX_PATH, "%s%s%s", dir.c_str(), gDirUtilp->getDirDelimiter().c_str(), found_file.c_str()); // Flawfinder: ignore 2766 old_vfs_data_file = dir + gDirUtilp->getDirDelimiter() + found_file;
2740 2767
2741 S32 start_pos; 2768 S32 start_pos = found_file.find_last_of('.');
2742 S32 length = strlen(found_file.c_str()); /* Flawfinder: ignore*/
2743 for (start_pos = length - 1; start_pos >= 0; start_pos--)
2744 {
2745 if (found_file[start_pos] == '.')
2746 {
2747 start_pos++;
2748 break;
2749 }
2750 }
2751 if (start_pos > 0) 2769 if (start_pos > 0)
2752 { 2770 {
2753 sscanf(found_file.c_str() + start_pos, "%d", &old_salt); 2771 sscanf(found_file.substr(start_pos+1).c_str(), "%d", &old_salt);
2754 } 2772 }
2755 LL_DEBUGS("AppCache") << "Default vfs data file not present, found: " << old_vfs_data_file << " Old salt: " << old_salt << llendl; 2773 LL_DEBUGS("AppCache") << "Default vfs data file not present, found: " << old_vfs_data_file << " Old salt: " << old_salt << llendl;
2756 } 2774 }
2757 } 2775 }
2758 2776
2759 snprintf(old_vfs_index_file, LL_MAX_PATH, "%s%u", // Flawfinder: ignore 2777 old_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_INDEX_FILE_BASE) + llformat("%u",old_salt);
2760 gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_INDEX_FILE_BASE).c_str(),
2761 old_salt);
2762 2778
2763 stat_result = LLFile::stat(old_vfs_index_file, &s); 2779 stat_result = LLFile::stat(old_vfs_index_file, &s);
2764 if (stat_result) 2780 if (stat_result)
@@ -2787,18 +2803,11 @@ bool LLAppViewer::initCache()
2787 gDirUtilp->deleteFilesInDir(dir, mask); 2803 gDirUtilp->deleteFilesInDir(dir, mask);
2788 } 2804 }
2789 2805
2790 snprintf(new_vfs_data_file, LL_MAX_PATH, "%s%u", // Flawfinder: ignore 2806 new_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE) + llformat("%u",new_salt);
2791 gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE).c_str(), 2807 new_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_INDEX_FILE_BASE) + llformat("%u",new_salt);
2792 new_salt);
2793 2808
2794 snprintf(new_vfs_index_file, LL_MAX_PATH, "%s%u", gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_INDEX_FILE_BASE).c_str(), // Flawfinder: ignore 2809 static_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_data.db2");
2795 new_salt); 2810 static_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_index.db2");
2796
2797
2798 strncpy(static_vfs_data_file, gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_data.db2").c_str(), LL_MAX_PATH -1); // Flawfinder: ignore
2799 static_vfs_data_file[LL_MAX_PATH -1] = '\0';
2800 strncpy(static_vfs_index_file, gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_index.db2").c_str(), LL_MAX_PATH -1); // Flawfinder: ignore
2801 static_vfs_index_file[LL_MAX_PATH -1] = '\0';
2802 2811
2803 if (resize_vfs) 2812 if (resize_vfs)
2804 { 2813 {
@@ -2849,15 +2858,15 @@ void LLAppViewer::purgeCache()
2849 LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << llendl; 2858 LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << llendl;
2850 LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE); 2859 LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
2851 std::string mask = gDirUtilp->getDirDelimiter() + "*.*"; 2860 std::string mask = gDirUtilp->getDirDelimiter() + "*.*";
2852 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"").c_str(),mask); 2861 gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""),mask);
2853} 2862}
2854 2863
2855const LLString& LLAppViewer::getSecondLifeTitle() const 2864const std::string& LLAppViewer::getSecondLifeTitle() const
2856{ 2865{
2857 return gSecondLife; 2866 return gSecondLife;
2858} 2867}
2859 2868
2860const LLString& LLAppViewer::getWindowTitle() const 2869const std::string& LLAppViewer::getWindowTitle() const
2861{ 2870{
2862 return gWindowTitle; 2871 return gWindowTitle;
2863} 2872}
@@ -2878,7 +2887,7 @@ void finish_forced_disconnect(S32 /* option */, void* /* userdata */)
2878} 2887}
2879 2888
2880 2889
2881void LLAppViewer::forceDisconnect(const LLString& mesg) 2890void LLAppViewer::forceDisconnect(const std::string& mesg)
2882{ 2891{
2883 if (gDoDisconnect) 2892 if (gDoDisconnect)
2884 { 2893 {
@@ -2888,13 +2897,13 @@ void LLAppViewer::forceDisconnect(const LLString& mesg)
2888 } 2897 }
2889 2898
2890 // Translate the message if possible 2899 // Translate the message if possible
2891 LLString big_reason = LLAgent::sTeleportErrorMessages[mesg]; 2900 std::string big_reason = LLAgent::sTeleportErrorMessages[mesg];
2892 if ( big_reason.size() == 0 ) 2901 if ( big_reason.size() == 0 )
2893 { 2902 {
2894 big_reason = mesg; 2903 big_reason = mesg;
2895 } 2904 }
2896 2905
2897 LLStringBase<char>::format_map_t args; 2906 LLStringUtil::format_map_t args;
2898 gDoDisconnect = TRUE; 2907 gDoDisconnect = TRUE;
2899 2908
2900 if (LLStartUp::getStartupState() < STATE_STARTED) 2909 if (LLStartUp::getStartupState() < STATE_STARTED)
@@ -2955,7 +2964,7 @@ void LLAppViewer::saveFinalSnapshot()
2955 gSavedSettings.setBOOL("ShowParcelOwners", FALSE); 2964 gSavedSettings.setBOOL("ShowParcelOwners", FALSE);
2956 idle(); 2965 idle();
2957 2966
2958 LLString snap_filename = gDirUtilp->getLindenUserDir(); 2967 std::string snap_filename = gDirUtilp->getLindenUserDir();
2959 snap_filename += gDirUtilp->getDirDelimiter(); 2968 snap_filename += gDirUtilp->getDirDelimiter();
2960 snap_filename += SCREEN_LAST_FILENAME; 2969 snap_filename += SCREEN_LAST_FILENAME;
2961 // use full pixel dimensions of viewer window (not post-scale dimensions) 2970 // use full pixel dimensions of viewer window (not post-scale dimensions)
@@ -2970,7 +2979,7 @@ void LLAppViewer::loadNameCache()
2970 2979
2971 std::string name_cache; 2980 std::string name_cache;
2972 name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache"); 2981 name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache");
2973 llifstream cache_file(name_cache.c_str()); 2982 llifstream cache_file(name_cache);
2974 if(cache_file.is_open()) 2983 if(cache_file.is_open())
2975 { 2984 {
2976 if(gCacheName->importFile(cache_file)) return; 2985 if(gCacheName->importFile(cache_file)) return;
@@ -2978,7 +2987,7 @@ void LLAppViewer::loadNameCache()
2978 2987
2979 // Try to load from the legacy format. This should go away after a 2988 // Try to load from the legacy format. This should go away after a
2980 // while. Phoenix 2008-01-30 2989 // while. Phoenix 2008-01-30
2981 LLFILE* name_cache_fp = LLFile::fopen(name_cache.c_str(), "r"); // Flawfinder: ignore 2990 LLFILE* name_cache_fp = LLFile::fopen(name_cache, "r"); // Flawfinder: ignore
2982 if (name_cache_fp) 2991 if (name_cache_fp)
2983 { 2992 {
2984 gCacheName->importFile(name_cache_fp); 2993 gCacheName->importFile(name_cache_fp);
@@ -2992,7 +3001,7 @@ void LLAppViewer::saveNameCache()
2992 3001
2993 std::string name_cache; 3002 std::string name_cache;
2994 name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache"); 3003 name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "name.cache");
2995 llofstream cache_file(name_cache.c_str()); 3004 llofstream cache_file(name_cache);
2996 if(cache_file.is_open()) 3005 if(cache_file.is_open())
2997 { 3006 {
2998 gCacheName->exportFile(cache_file); 3007 gCacheName->exportFile(cache_file);
@@ -3023,10 +3032,13 @@ public:
3023/////////////////////////////////////////////////////// 3032///////////////////////////////////////////////////////
3024void LLAppViewer::idle() 3033void LLAppViewer::idle()
3025{ 3034{
3035 pingMainloopTimeout("Main:Idle");
3036
3026 // Update frame timers 3037 // Update frame timers
3027 static LLTimer idle_timer; 3038 static LLTimer idle_timer;
3028 3039
3029 LLFrameTimer::updateFrameTime(); 3040 LLFrameTimer::updateFrameTime();
3041 LLFrameTimer::updateFrameCount();
3030 LLEventTimer::updateClass(); 3042 LLEventTimer::updateClass();
3031 LLCriticalDamp::updateInterpolants(); 3043 LLCriticalDamp::updateInterpolants();
3032 LLMortician::updateClass(); 3044 LLMortician::updateClass();
@@ -3434,9 +3446,7 @@ void LLAppViewer::idleShutdown()
3434 S32 finished_uploads = total_uploads - pending_uploads; 3446 S32 finished_uploads = total_uploads - pending_uploads;
3435 F32 percent = 100.f * finished_uploads / total_uploads; 3447 F32 percent = 100.f * finished_uploads / total_uploads;
3436 gViewerWindow->setProgressPercent(percent); 3448 gViewerWindow->setProgressPercent(percent);
3437 char buffer[MAX_STRING]; // Flawfinder: ignore 3449 gViewerWindow->setProgressString("Saving final data...");
3438 snprintf(buffer, MAX_STRING, "Saving final data..."); // Flawfinder: ignore
3439 gViewerWindow->setProgressString(buffer);
3440 return; 3450 return;
3441 } 3451 }
3442 3452
@@ -3598,6 +3608,23 @@ void LLAppViewer::idleNetwork()
3598 gAssetStorage->checkForTimeouts(); 3608 gAssetStorage->checkForTimeouts();
3599 3609
3600 gViewerThrottle.updateDynamicThrottle(); 3610 gViewerThrottle.updateDynamicThrottle();
3611
3612
3613 // Check that the circuit between the viewer and the agent's current
3614 // region is still alive
3615 LLViewerRegion *agent_region = gAgent.getRegion();
3616 if (agent_region)
3617 {
3618 LLUUID this_region_id = agent_region->getRegionID();
3619 bool this_region_alive = agent_region->isAlive();
3620 if ((mAgentRegionLastAlive && !this_region_alive) // newly dead
3621 && (mAgentRegionLastID == this_region_id)) // same region
3622 {
3623 forceDisconnect(LLTrans::getString("AgentLostConnection"));
3624 }
3625 mAgentRegionLastID = this_region_id;
3626 mAgentRegionLastAlive = this_region_alive;
3627 }
3601} 3628}
3602 3629
3603void LLAppViewer::disconnectViewer() 3630void LLAppViewer::disconnectViewer()
@@ -3748,4 +3775,3 @@ void LLAppViewer::pingMainloopTimeout(const std::string& state, F32 secs)
3748 } 3775 }
3749} 3776}
3750 3777
3751