From ffdc04f5d2b2d952ace912a473b11f4305e9d057 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Thu, 21 Apr 2022 22:58:30 +0300
Subject: [PATCH] SL-17040 Crash due to LLWord not existing

LLWord should persist till the end due to wide usage.
---
 indra/newview/llappviewer.cpp | 3 ++-
 indra/newview/llstartup.cpp   | 2 +-
 indra/newview/llworld.cpp     | 3 +--
 indra/newview/llworld.h       | 4 +++-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index f89ab586d53..a63203f3cba 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2161,6 +2161,7 @@ bool LLAppViewer::cleanup()
 	LLEnvironment::deleteSingleton();
 	LLSelectMgr::deleteSingleton();
 	LLViewerEventRecorder::deleteSingleton();
+    LLWorld::deleteSingleton();
 
 	// It's not at first obvious where, in this long sequence, a generic cleanup
 	// call OUGHT to go. So let's say this: as we migrate cleanup from
@@ -5421,7 +5422,7 @@ void LLAppViewer::disconnectViewer()
 	// Now we just ask the LLWorld singleton to cleanly shut down.
 	if(LLWorld::instanceExists())
 	{
-		LLWorld::getInstance()->destroyClass();
+		LLWorld::getInstance()->resetClass();
 	}
 	LLVOCache::deleteSingleton();
 
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index 8912d1cff16..5df8cd9cb0b 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -2841,7 +2841,7 @@ void reset_login()
 	gAgentWearables.cleanup();
 	gAgentCamera.cleanup();
 	gAgent.cleanup();
-	LLWorld::getInstance()->destroyClass();
+	LLWorld::getInstance()->resetClass();
 
 	if ( gViewerWindow )
 	{	// Hide menus and normal buttons
diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp
index 82629fd7370..8abb49fba8b 100644
--- a/indra/newview/llworld.cpp
+++ b/indra/newview/llworld.cpp
@@ -113,7 +113,7 @@ LLWorld::LLWorld() :
 }
 
 
-void LLWorld::destroyClass()
+void LLWorld::resetClass()
 {
 	mHoleWaterObjects.clear();
 	gObjectList.destroy();
@@ -135,7 +135,6 @@ void LLWorld::destroyClass()
 	LLDrawable::incrementVisible();
 
 	LLSceneMonitor::deleteSingleton();
-    LLWorld::deleteSingleton();
 }
 
 
diff --git a/indra/newview/llworld.h b/indra/newview/llworld.h
index 69f2df42032..5c43cdf4e27 100644
--- a/indra/newview/llworld.h
+++ b/indra/newview/llworld.h
@@ -64,7 +64,9 @@ class LLWorld : public LLSimpleton<LLWorld>
 public:
     LLWorld();
 
-    void destroyClass();
+    // Clear any objects, regions
+    // Prepares class to be reused or destroyed
+    void resetClass();
 
 	LLViewerRegion*	addRegion(const U64 &region_handle, const LLHost &host);
 		// safe to call if already present, does the "right thing" if
-- 
GitLab