From 1aad201a98ded682e5704ec6cce412f58f541dbb Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Tue, 15 Jun 2021 10:51:36 -0500 Subject: [PATCH] [LYN-4527] Make sure the PrefabIntegrationManager is only created when prefabs are enabled, otherwise could result in crashes. --- .../SandboxIntegration.cpp | 27 +++++++++++++++---- .../SandboxIntegration.h | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp index 3b04fc70f8..82d74d5d00 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp @@ -154,11 +154,23 @@ SandboxIntegrationManager::SandboxIntegrationManager() { // Required to receive events from the Cry Engine undo system GetIEditor()->GetUndoManager()->AddListener(this); + + // Only create the PrefabIntegrationManager if prefabs are enabled + bool prefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult( + prefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + if (prefabSystemEnabled) + { + m_prefabIntegrationManager = aznew AzToolsFramework::Prefab::PrefabIntegrationManager(); + } } SandboxIntegrationManager::~SandboxIntegrationManager() { GetIEditor()->GetUndoManager()->RemoveListener(this); + + delete m_prefabIntegrationManager; + m_prefabIntegrationManager = nullptr; } void SandboxIntegrationManager::Setup() @@ -187,11 +199,16 @@ void SandboxIntegrationManager::Setup() AZ_Assert((m_editorEntityUiInterface != nullptr), "SandboxIntegrationManager requires a EditorEntityUiInterface instance to be present on Setup()."); - m_prefabIntegrationInterface = AZ::Interface::Get(); - - AZ_Assert( - (m_prefabIntegrationInterface != nullptr), - "SandboxIntegrationManager requires a PrefabIntegrationInterface instance to be present on Setup()."); + bool prefabSystemEnabled = false; + AzFramework::ApplicationRequests::Bus::BroadcastResult( + prefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); + if (prefabSystemEnabled) + { + m_prefabIntegrationInterface = AZ::Interface::Get(); + AZ_Assert( + (m_prefabIntegrationInterface != nullptr), + "SandboxIntegrationManager requires a PrefabIntegrationInterface instance to be present on Setup()."); + } m_editorEntityAPI = AZ::Interface::Get(); AZ_Assert(m_editorEntityAPI, "SandboxIntegrationManager requires an EditorEntityAPI instance to be present on Setup()."); diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h index 5cb03cc99f..b734d4d361 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h @@ -305,7 +305,7 @@ private: bool m_debugDisplayBusImplementationActive = false; - AzToolsFramework::Prefab::PrefabIntegrationManager m_prefabIntegrationManager; + AzToolsFramework::Prefab::PrefabIntegrationManager* m_prefabIntegrationManager = nullptr; AzToolsFramework::EditorEntityUiInterface* m_editorEntityUiInterface = nullptr; AzToolsFramework::Prefab::PrefabIntegrationInterface* m_prefabIntegrationInterface = nullptr;