From 7d7b60a9bec597e2a769ab9e798315194bd6294a Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Tue, 22 Oct 2019 17:47:44 +0300
Subject: [PATCH] SL-12168 FIXED crash on exit, if resetting camera was
 performed

---
 indra/newview/llagentcamera.cpp    | 5 +++++
 indra/newview/llappviewer.cpp      | 5 +++++
 indra/newview/llviewerkeyboard.cpp | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp
index fd8797481d0..c9074d1a952 100644
--- a/indra/newview/llagentcamera.cpp
+++ b/indra/newview/llagentcamera.cpp
@@ -282,6 +282,11 @@ LLAgentCamera::~LLAgentCamera()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::resetView(BOOL reset_camera, BOOL change_camera)
 {
+	if (gDisconnected)
+	{
+		return;
+	}
+
 	if (gAgent.getAutoPilot())
 	{
 		gAgent.stopAutoPilot(TRUE);
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index b704bf84a1a..228dd36e536 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1719,6 +1719,11 @@ bool LLAppViewer::cleanup()
 	disconnectViewer();
 
 	LL_INFOS() << "Viewer disconnected" << LL_ENDL;
+	
+	if (gKeyboard)
+	{
+		gKeyboard->resetKeys();
+	}
 
 	display_cleanup();
 
diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp
index e930eb20d3c..a14041717f2 100644
--- a/indra/newview/llviewerkeyboard.cpp
+++ b/indra/newview/llviewerkeyboard.cpp
@@ -986,6 +986,11 @@ EKeyboardMode LLViewerKeyboard::getMode()
 // Called from scanKeyboard.
 void LLViewerKeyboard::scanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level)
 {
+	if (LLApp::isExiting())
+	{
+		return;
+	}
+
 	S32 mode = getMode();
 	// Consider keyboard scanning as NOT mouse event. JC
 	MASK mask = gKeyboard->currentMask(FALSE);
-- 
GitLab