[development] removed CryLibrary (#5474)

* [redcode_crylibrary] replaced CrySystem loading in launcher and editor with new custom wrapper that uses AZ::DynamicModuleHandle

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>

* [redcode_crylibrary] removed all remaining references to CryLibrary

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>

* [redcode_crylibrary] migrate CrySystem loading to use AZ::DynamicModuleHandle directly instead

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>

* [redcode_crylibrary] clean up of CrySystemModuleHandle and old CrySystem module [un]init functions

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>

* [redcode_crylibrary] added trailing newline to DllMain.cpp in CrySystem

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
Scott Romero
2021-11-10 08:43:13 -08:00
committed by GitHub
parent 8b5fe4a015
commit ab37eb138c
17 changed files with 24 additions and 527 deletions
+6 -147
View File
@@ -25,7 +25,6 @@
#include <AzGameFramework/Application/GameApplication.h>
#include <CryLibrary.h>
#include <ISystem.h>
#include <ITimer.h>
#include <LegacyAllocator.h>
@@ -80,146 +79,6 @@ namespace
}
}
#if AZ_TRAIT_LAUNCHER_USE_CRY_DYNAMIC_MODULE_HANDLE
// mimics AZ::DynamicModuleHandle but uses CryLibrary under the hood,
// which is necessary to properly load legacy Cry libraries on some platforms
class DynamicModuleHandle
{
public:
AZ_CLASS_ALLOCATOR(DynamicModuleHandle, AZ::OSAllocator, 0)
static AZStd::unique_ptr<DynamicModuleHandle> Create(const char* fullFileName)
{
return AZStd::unique_ptr<DynamicModuleHandle>(aznew DynamicModuleHandle(fullFileName));
}
DynamicModuleHandle(const DynamicModuleHandle&) = delete;
DynamicModuleHandle& operator=(const DynamicModuleHandle&) = delete;
~DynamicModuleHandle()
{
Unload();
}
// argument is strictly to match the API of AZ::DynamicModuleHandle
bool Load(bool unused)
{
AZ_UNUSED(unused);
if (IsLoaded())
{
return true;
}
m_moduleHandle = CryLoadLibrary(m_fileName.c_str());
return IsLoaded();
}
bool Unload()
{
if (!IsLoaded())
{
return false;
}
return CryFreeLibrary(m_moduleHandle);
}
bool IsLoaded() const
{
return m_moduleHandle != nullptr;
}
const AZ::OSString& GetFilename() const
{
return m_fileName;
}
template<typename Function>
Function GetFunction(const char* functionName) const
{
if (IsLoaded())
{
return reinterpret_cast<Function>(CryGetProcAddress(m_moduleHandle, functionName));
}
else
{
return nullptr;
}
}
private:
DynamicModuleHandle(const char* fileFullName)
: m_fileName()
, m_moduleHandle(nullptr)
{
m_fileName = AZ::OSString::format("%s%s%s",
CrySharedLibraryPrefix, fileFullName, CrySharedLibraryExtension);
}
AZ::OSString m_fileName;
HMODULE m_moduleHandle;
};
#else
// mimics AZ::DynamicModuleHandle but also calls InjectEnvironmentFunction on
// the loaded module which is necessary to properly load legacy Cry libraries
class DynamicModuleHandle
{
public:
AZ_CLASS_ALLOCATOR(DynamicModuleHandle, AZ::OSAllocator, 0);
static AZStd::unique_ptr<DynamicModuleHandle> Create(const char* fullFileName)
{
return AZStd::unique_ptr<DynamicModuleHandle>(aznew DynamicModuleHandle(fullFileName));
}
bool Load(bool isInitializeFunctionRequired)
{
const bool loaded = m_moduleHandle->Load(isInitializeFunctionRequired);
if (loaded)
{
// We need to inject the environment first thing so that allocators are available immediately
InjectEnvironmentFunction injectEnv = GetFunction<InjectEnvironmentFunction>(INJECT_ENVIRONMENT_FUNCTION);
if (injectEnv)
{
auto env = AZ::Environment::GetInstance();
injectEnv(env);
}
}
return loaded;
}
bool Unload()
{
bool unloaded = m_moduleHandle->Unload();
if (unloaded)
{
DetachEnvironmentFunction detachEnv = GetFunction<DetachEnvironmentFunction>(DETACH_ENVIRONMENT_FUNCTION);
if (detachEnv)
{
detachEnv();
}
}
return unloaded;
}
template<typename Function>
Function GetFunction(const char* functionName) const
{
return m_moduleHandle->GetFunction<Function>(functionName);
}
private:
DynamicModuleHandle(const char* fileFullName)
: m_moduleHandle(AZ::DynamicModuleHandle::Create(fileFullName))
{
}
AZStd::unique_ptr<AZ::DynamicModuleHandle> m_moduleHandle;
};
#endif // AZ_TRAIT_LAUNCHER_USE_CRY_DYNAMIC_MODULE_HANDLE
void RunMainLoop(AzGameFramework::GameApplication& gameApplication)
{
// Ideally we'd just call GameApplication::RunMainLoop instead, but
@@ -649,13 +508,13 @@ namespace O3DELauncher
// Create CrySystem.
#if !defined(AZ_MONOLITHIC_BUILD)
AZStd::unique_ptr<DynamicModuleHandle> crySystemLibrary;
PFNCREATESYSTEMINTERFACE CreateSystemInterface = nullptr;
crySystemLibrary = DynamicModuleHandle::Create("CrySystem");
if (crySystemLibrary->Load(false))
constexpr const char* crySystemLibraryName = AZ_TRAIT_OS_DYNAMIC_LIBRARY_PREFIX "CrySystem" AZ_TRAIT_OS_DYNAMIC_LIBRARY_EXTENSION;
AZStd::unique_ptr<AZ::DynamicModuleHandle> crySystemLibrary = AZ::DynamicModuleHandle::Create(crySystemLibraryName);
if (crySystemLibrary->Load(true))
{
CreateSystemInterface = crySystemLibrary->GetFunction<PFNCREATESYSTEMINTERFACE>("CreateSystemInterface");
PFNCREATESYSTEMINTERFACE CreateSystemInterface =
crySystemLibrary->GetFunction<PFNCREATESYSTEMINTERFACE>("CreateSystemInterface");
if (CreateSystemInterface)
{
systemInitParams.pSystem = CreateSystemInterface(systemInitParams);
@@ -12,8 +12,6 @@
#include <AzCore/IO/SystemFile.h> // for AZ_MAX_PATH_LEN
#include <AzCore/Math/Vector2.h>
#include <CryLibrary.h>
#include <execinfo.h>
#include <libgen.h>
#include <netdb.h>
@@ -86,17 +84,6 @@ int main(int argc, char** argv)
using namespace O3DELauncher;
#if !defined(AZ_MONOLITHIC_BUILD)
char exePath[AZ_MAX_PATH_LEN] = { 0 };
if (readlink("/proc/self/exe", exePath, AZ_MAX_PATH_LEN) == -1)
{
return static_cast<int>(ReturnCode::ErrExePath);
}
char* runDir = dirname(exePath);
SetModulePath(runDir);
#endif // !defined(AZ_MONOLITHIC_BUILD)
PlatformMainInfo mainInfo;
mainInfo.m_updateResourceLimits = IncreaseResourceLimits;
@@ -7,7 +7,6 @@
*/
#include <Launcher.h>
#include <CryCommon/CryLibrary.h>
#include <AzCore/Math/Vector2.h>
#include <AzCore/Memory/SystemAllocator.h>
@@ -43,24 +42,6 @@ int APIENTRY WinMain([[maybe_unused]] HINSTANCE hInstance, [[maybe_unused]] HINS
MessageBoxA(0, GetReturnCodeString(status), "Error", MB_OK | MB_DEFAULT_DESKTOP_ONLY | MB_ICONERROR);
}
#if !defined(AZ_MONOLITHIC_BUILD)
{
// HACK HACK HACK - is this still needed?!?!
// CrySystem module can get loaded multiple times (even from within CrySystem itself)
// so we will release it as many times as it takes until it actually unloads.
void* hModule = CryLoadLibraryDefName("CrySystem");
if (hModule)
{
// loop until we fail (aka unload the DLL)
while (CryFreeLibrary(hModule))
{
;
}
}
}
#endif // !defined(AZ_MONOLITHIC_BUILD)
// there is no way to transfer ownership of the allocator to the component application
// without altering the app descriptor, so it must be destroyed here
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();