Bladeren bron

Remove calls to Environment `Create`/`Destroy`/`IsReady`/`Attach`/`Detach`

These calls don't do anything anymore. The Environment is created on demand
so it is always ready, and will be destroyed after the first thing that
asked for it. Attach and Detach are meaningless now that the Environment is
provided by a shared library.

Signed-off-by: Chris Burel <[email protected]>
Chris Burel 3 jaren geleden
bovenliggende
commit
ba30f0e550

+ 0 - 2
Code/Editor/Core/Tests/test_Main.cpp

@@ -33,7 +33,6 @@ public:
 protected:
     void SetupEnvironment() override
     {
-        AttachEditorCoreAZEnvironment(AZ::Environment::GetInstance());
         m_allocatorScope.ActivateAllocators();
         m_cryPak = new NiceMock<CryPakMock>();
 
@@ -50,7 +49,6 @@ protected:
     {
         delete m_cryPak;
         m_allocatorScope.DeactivateAllocators();
-        DetachEditorCoreAZEnvironment();
     }
 
 private:

+ 1 - 12
Code/Editor/CryEdit.cpp

@@ -1573,8 +1573,6 @@ bool CCryEditApp::InitInstance()
     QElapsedTimer startupTimer;
     startupTimer.start();
 
-    // create / attach to the environment:
-    AttachEditorCoreAZEnvironment(AZ::Environment::GetInstance());
     m_pEditor = new CEditorImpl();
 
     // parameters must be parsed early to capture arguments for test bootstrap
@@ -2165,7 +2163,6 @@ int CCryEditApp::ExitInstance(int exitCode)
         delete m_mutexApplication;
     }
 
-    DetachEditorCoreAZEnvironment();
     return 0;
 }
 
@@ -3955,14 +3952,6 @@ extern "C" int AZ_DLL_EXPORT CryEditMain(int argc, char* argv[])
     return ret;
 }
 
-extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* env)
-{
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(env));
-}
-
-extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
-{
-    AZ::Environment::Detach();
-}
+AZ_DECLARE_MODULE_INITIALIZATION
 
 #include <moc_CryEdit.cpp>

+ 0 - 10
Code/Editor/EditorEnvironment.cpp

@@ -14,13 +14,3 @@ void SetEditorEnvironment(SSystemGlobalEnvironment* pEnv)
     assert(!gEnv || gEnv != pEnv);
     gEnv = pEnv;
 }
-
-void AttachEditorAZEnvironment(AZ::EnvironmentInstance azEnv)
-{
-    AZ::Environment::Attach(azEnv);
-}
-
-void DetachEditorAZEnvironment()
-{
-    AZ::Environment::Detach();
-}

+ 0 - 4
Code/Editor/EditorEnvironment.h

@@ -11,7 +11,3 @@
 #include <AzCore/Module/Environment.h>
 
 SANDBOX_API void  SetEditorEnvironment(struct SSystemGlobalEnvironment* pEnv);
-
-SANDBOX_API void AttachEditorAZEnvironment(AZ::EnvironmentInstance azEnv);
-
-SANDBOX_API void DetachEditorAZEnvironment();

+ 0 - 10
Code/Editor/Include/EditorCoreAPI.cpp

@@ -43,13 +43,3 @@ void SetEditorCoreEnvironment(SSystemGlobalEnvironment* pEnv)
     assert(!gEnv);
     gEnv = pEnv;
 }
-
-void AttachEditorCoreAZEnvironment(AZ::EnvironmentInstance pAzEnv)
-{
-    AZ::Environment::Attach(pAzEnv);
-}
-
-void DetachEditorCoreAZEnvironment()
-{
-    AZ::Environment::Detach();
-}

+ 0 - 6
Code/Editor/Include/EditorCoreAPI.h

@@ -43,12 +43,6 @@ EDITOR_CORE_API IEditor* GetIEditor();
 //! Attach the editorcore dll to the system environmen in the System DLL
 EDITOR_CORE_API void SetEditorCoreEnvironment(struct SSystemGlobalEnvironment* pEnv);
 
-//! Attach the editorcore dll to the AZ Environment which allows ebus and memory allocation - should be done really early
-EDITOR_CORE_API void AttachEditorCoreAZEnvironment(AZ::EnvironmentInstance pAzEnv);
-
-//! Detach the editorcore dll from the AZ Environment, should be done last.
-EDITOR_CORE_API void DetachEditorCoreAZEnvironment();
-
 #if defined(AZ_PLATFORM_WINDOWS)
 #include "../IEditor.h"
 #endif

+ 0 - 4
Code/Editor/Lib/Tests/test_Main.cpp

@@ -25,16 +25,12 @@ protected:
     {
         ::UnitTest::TraceBusHook::SetupEnvironment();
 
-        AZ::Environment::Create(nullptr);
         AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
-        AttachEditorAZEnvironment(AZ::Environment::GetInstance());
     }
 
     void TeardownEnvironment() override
     {
-        DetachEditorAZEnvironment();
         AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
-        AZ::Environment::Destroy();
 
         ::UnitTest::TraceBusHook::TeardownEnvironment();
     }

+ 0 - 2
Code/Editor/main.cpp

@@ -19,7 +19,6 @@ int main(int argc, char* argv[])
     using CryEditMain = int (*)(int, char*[]);
     constexpr const char CryEditMainName[] = "CryEditMain";
 
-    AZ::Environment::Attach(AZ::Environment::GetInstance());
     AZ::AllocatorInstance<AZ::OSAllocator>::Create();
 
     auto handle = AZ::DynamicModuleHandle::Create("EditorLib");
@@ -34,6 +33,5 @@ int main(int argc, char* argv[])
 
     handle = {};
     AZ::AllocatorInstance<AZ::OSAllocator>::Destroy();
-    AZ::Environment::Detach();
     return ret;
 }

+ 1 - 1
Code/Framework/AzCore/AzCore/EBus/Environment.h

@@ -250,7 +250,7 @@ namespace AZ
     template<class Context>
     Context* EBusEnvironmentStoragePolicy<Context>::Get()
     {
-        if (!s_defaultGlobalContext && Environment::IsReady())
+        if (!s_defaultGlobalContext)
         {
             s_defaultGlobalContext = Environment::FindVariable<Context>(GetVariableId());
         }

+ 0 - 6
Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h

@@ -37,12 +37,6 @@ namespace UnitTest
 
         void SetupAllocator(const AZ::SystemAllocator::Descriptor& allocatorDesc = {})
         {
-            // Make sure an instance of AZ::Environment exists for AZ::AllocatorManager
-            if (!AZ::Environment::IsReady())
-            {
-                AZ::Environment::Create(nullptr);
-            }
-
             AZ::AllocatorManager::Instance().EnterProfilingMode();
             AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL);
 

+ 0 - 3
Code/Framework/AzCore/Tests/DLLMainTest.cpp

@@ -107,7 +107,6 @@ extern "C" AZ_DLL_EXPORT void DestroyDLLTestVirtualClass()
 
 extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* azEnvironmentInstance)
 {
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(azEnvironmentInstance));
     AZ_Assert(AZ::Environment::GetInstance() == azEnvironmentInstance, "Invalid!");
     AZ_Printf("DLL", "InitializeDynamicModule called");
 }
@@ -127,6 +126,4 @@ extern "C" AZ_DLL_EXPORT void DestroyModuleClass(AZ::Module* module)
 extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
 {
     AZ_Printf("DLL", "UninitializeDynamicModule called");
-
-    AZ::Environment::Detach();
 }

+ 0 - 5
Code/Legacy/CrySystem/DllMain.cpp

@@ -70,11 +70,6 @@ ISystem* CreateSystemInterface(const SSystemInitParams& startupParams)
 {
     CSystem* pSystem = NULL;
 
-    // We must attach to the environment prior to allocating CSystem, as opposed to waiting
-    // for ModuleInitISystem(), because the log message sink uses buses.
-    // Environment should have been attached via InitializeDynamicModule
-    AZ_Assert(AZ::Environment::IsReady(), "Environment is not attached, must be attached before CreateSystemInterface can be called");
-
     pSystem = new CSystem(startupParams.pSharedEnvironment);
     ModuleInitISystem(pSystem, "CrySystem");
 

+ 0 - 2
Code/Legacy/CrySystem/System.cpp

@@ -291,8 +291,6 @@ CSystem::~CSystem()
         AZ::AllocatorInstance<AZ::OSAllocator>::Destroy();
     }
 
-    AZ::Environment::Detach();
-
     m_env.pSystem = 0;
     gEnv = 0;
 }

+ 0 - 2
Code/Tools/AssetProcessor/native/tests/BaseAssetProcessorTest.h

@@ -40,14 +40,12 @@ protected:
     void SetupEnvironment() override
     {
         // Setup code
-        AZ::Environment::Create(nullptr);
         qInstallMessageHandler(UnitTestMessageHandler);
     }
 
     void TeardownEnvironment() override
     {
         qInstallMessageHandler(nullptr);
-        AZ::Environment::Destroy();
     }
 
 private:

+ 1 - 3
Code/Tools/SceneAPI/SceneBuilder/DllMain.cpp

@@ -101,9 +101,8 @@ namespace AZ
     } // namespace SceneAPI
 } // namespace AZ
 
-extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* env)
+extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* /*env*/)
 {
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(env));
 }
 extern "C" AZ_DLL_EXPORT void Reflect(AZ::SerializeContext* context)
 {
@@ -116,7 +115,6 @@ extern "C" AZ_DLL_EXPORT void ReflectBehavior(AZ::BehaviorContext* context)
 extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
 {
     AZ::SceneAPI::SceneBuilder::Uninitialize();
-    AZ::Environment::Detach();
 }
 
 #endif // !defined(AZ_MONOLITHIC_BUILD)

+ 8 - 7
Code/Tools/SceneAPI/SceneCore/DllMain.cpp

@@ -284,14 +284,15 @@ namespace AZ
     } // namespace SceneAPI
 } // namespace AZ
 
-extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* env)
+static bool g_sceneCoreInitialized = false;
+
+extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* /*env*/)
 {
-    if (AZ::Environment::IsReady())
+    if (g_sceneCoreInitialized)
     {
         return;
     }
-
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(env));
+    g_sceneCoreInitialized = true;
 
     AZ::SceneAPI::SceneCore::Initialize();
 }
@@ -323,10 +324,12 @@ extern "C" AZ_DLL_EXPORT void Deactivate()
 
 extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
 {
-    if (!AZ::Environment::IsReady())
+    if (!g_sceneCoreInitialized)
     {
         return;
     }
+    g_sceneCoreInitialized = false;
+
     AZ::SceneAPI::SceneCore::Uninitialize();
 
     // This module does not own these allocators, but must clear its cached EnvironmentVariables
@@ -339,8 +342,6 @@ extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
     {
         AZ::AllocatorInstance<AZ::OSAllocator>::Destroy();
     }
-
-    AZ::Environment::Detach();
 }
 
 #endif // !defined(AZ_MONOLITHIC_BUILD)

+ 1 - 3
Code/Tools/SceneAPI/SceneCore/SceneCoreStandaloneAllocator.cpp

@@ -16,9 +16,8 @@ namespace AZ
     {
         bool SceneCoreStandaloneAllocator::m_allocatorInitialized = false;
 
-        void SceneCoreStandaloneAllocator::Initialize(AZ::EnvironmentInstance environment)
+        void SceneCoreStandaloneAllocator::Initialize(AZ::EnvironmentInstance /*environment*/)
         {
-            AZ::Environment::Attach(environment);
             if (!AZ::AllocatorInstance<AZ::SystemAllocator>().IsReady())
             {
                 AZ::AllocatorInstance<AZ::SystemAllocator>().Create();
@@ -32,7 +31,6 @@ namespace AZ
             {
                 AZ::AllocatorInstance<AZ::SystemAllocator>().Destroy();
             }
-            AZ::Environment::Detach();
         }
     }
 }

+ 0 - 2
Code/Tools/SceneAPI/SceneCore/Tests/TestsMain.cpp

@@ -19,14 +19,12 @@ public:
 protected:
     void SetupEnvironment() override
     {
-        AZ::Environment::Create(nullptr);
         AZ::SceneAPI::SceneCoreStandaloneAllocator::Initialize(AZ::Environment::GetInstance());
     }
 
     void TeardownEnvironment() override
     {
         AZ::SceneAPI::SceneCoreStandaloneAllocator::TearDown();
-        AZ::Environment::Destroy();
     }
 };
 

+ 7 - 7
Code/Tools/SceneAPI/SceneData/DllMain.cpp

@@ -106,14 +106,15 @@ namespace AZ {
     } // namespace SceneAPI
 } // namespace AZ
 
-extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* env)
+static bool g_sceneDataInitialized = false;
+
+extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* /*env*/)
 {
-    if (AZ::Environment::IsReady())
+    if (g_sceneDataInitialized)
     {
         return;
     }
-
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(env));
+    g_sceneDataInitialized = true;
 
     AZ::SceneAPI::SceneData::Initialize();
 }
@@ -130,10 +131,11 @@ extern "C" AZ_DLL_EXPORT void ReflectBehavior(AZ::BehaviorContext * context)
 
 extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
 {
-    if (!AZ::Environment::IsReady())
+    if (!g_sceneDataInitialized)
     {
         return;
     }
+    g_sceneDataInitialized = false;
 
     AZ::SceneAPI::SceneData::Uninitialize();
 
@@ -147,8 +149,6 @@ extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
     {
         AZ::AllocatorInstance<AZ::OSAllocator>::Destroy();
     }
-
-    AZ::Environment::Detach();
 }
 
 #endif // !defined(AZ_MONOLITHIC_BUILD)

+ 1 - 3
Code/Tools/SceneAPI/SceneData/SceneDataStandaloneAllocator.cpp

@@ -16,9 +16,8 @@ namespace AZ
     {
         bool SceneDataStandaloneAllocator::m_allocatorInitialized = false;
 
-        void SceneDataStandaloneAllocator::Initialize(AZ::EnvironmentInstance environment)
+        void SceneDataStandaloneAllocator::Initialize(AZ::EnvironmentInstance /*environment*/)
         {
-            AZ::Environment::Attach(environment);
             if (!AZ::AllocatorInstance<AZ::SystemAllocator>().IsReady())
             {
                 AZ::AllocatorInstance<AZ::SystemAllocator>().Create();
@@ -32,7 +31,6 @@ namespace AZ
             {
                 AZ::AllocatorInstance<AZ::SystemAllocator>().Destroy();
             }
-            AZ::Environment::Detach();
         }
     }
 }

+ 0 - 2
Code/Tools/SceneAPI/SceneData/Tests/TestsMain.cpp

@@ -21,7 +21,6 @@ public:
 protected:
     void SetupEnvironment() override
     {
-        AZ::Environment::Create(nullptr);
         AZ::SceneAPI::SceneDataStandaloneAllocator::Initialize(AZ::Environment::GetInstance());
 
         sceneCoreModule = AZ::DynamicModuleHandle::Create("SceneCore");
@@ -40,7 +39,6 @@ protected:
         (*uninit)();
         sceneCoreModule.reset();
         AZ::SceneAPI::SceneDataStandaloneAllocator::TearDown();
-        AZ::Environment::Destroy();
     }
 
 private:

+ 1 - 5
Code/Tools/SceneAPI/SceneUI/DllMain.cpp

@@ -22,10 +22,8 @@
 static AZ::SceneAPI::UI::GraphMetaInfoHandler* g_graphMetaInfoHandler = nullptr;
 static AZ::SceneAPI::UI::ManifestMetaInfoHandler* g_manifestMetaInfoHandler = nullptr;
 
-extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* env)
+extern "C" AZ_DLL_EXPORT void InitializeDynamicModule(void* /*env*/)
 {
-    AZ::Environment::Attach(static_cast<AZ::EnvironmentInstance>(env));
-
     AZ::SceneAPI::UI::HeaderHandler::Register();
     AZ::SceneAPI::UI::NodeListSelectionHandler::Register();
     AZ::SceneAPI::UI::NodeTreeSelectionHandler::Register();
@@ -61,6 +59,4 @@ extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
     AZ::SceneAPI::UI::NodeTreeSelectionHandler::Unregister();
     AZ::SceneAPI::UI::NodeListSelectionHandler::Unregister();
     AZ::SceneAPI::UI::HeaderHandler::Unregister();
-    
-    AZ::Environment::Detach();
 }