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