diff --git a/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp b/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp index e1b93ee5..d07eab4c 100644 --- a/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp +++ b/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp @@ -34,11 +34,14 @@ void UImmutableSubsystem::Initialize(FSubsystemCollectionBase &Collection) { this, &UImmutableSubsystem::WorldTickStart); } -void UImmutableSubsystem::Deinitialize() { - IMTBL_LOG_FUNCSIG - BrowserWidget = nullptr; - ImtblBlui = nullptr; - Passport = nullptr; +void UImmutableSubsystem::Deinitialize() +{ + IMTBL_LOG_FUNCSIG + BrowserWidget = nullptr; + IMTBL_LOG("Stopped BLUI event loop"); + ImtblBlui->StopBluiEventLoop(); + ImtblBlui = nullptr; + Passport = nullptr; #if PLATFORM_ANDROID | PLATFORM_IOS UGameViewportClient::OnViewportCreated().Remove(EngineInitCompleteHandle); #else diff --git a/Source/Immutable/Private/Immutable/ImtblBlui.cpp b/Source/Immutable/Private/Immutable/ImtblBlui.cpp index ffe03772..b4794284 100644 --- a/Source/Immutable/Private/Immutable/ImtblBlui.cpp +++ b/Source/Immutable/Private/Immutable/ImtblBlui.cpp @@ -150,3 +150,13 @@ void UImtblBlui::Init() { JSConnector->Init(!BluEye->IsBrowserLoading()); #endif } + +#if USING_BLUI_CEF +void UImtblBlui::StopBluiEventLoop() +{ + if (UBluEye* BluEye = GetBluEye()) + { + BluEye->SetShouldTickEventLoop(false); + } +} +#endif diff --git a/Source/Immutable/Private/Immutable/ImtblBlui.h b/Source/Immutable/Private/Immutable/ImtblBlui.h index 2b2d047e..47a1ee67 100644 --- a/Source/Immutable/Private/Immutable/ImtblBlui.h +++ b/Source/Immutable/Private/Immutable/ImtblBlui.h @@ -28,6 +28,10 @@ class IMMUTABLE_API UImtblBlui : public UObject { void BeginDestroy() override; void Init(); +#if USING_BLUI_CEF + void StopBluiEventLoop(); +#endif + private: UPROPERTY() UObject *BluEyePtr = nullptr; diff --git a/Source/Immutable/Private/ImmutableModule.cpp b/Source/Immutable/Private/ImmutableModule.cpp index 21f9b286..aed6b795 100644 --- a/Source/Immutable/Private/ImmutableModule.cpp +++ b/Source/Immutable/Private/ImmutableModule.cpp @@ -4,6 +4,12 @@ #include "Immutable/Misc/ImtblLogging.h" #include "Interfaces/IPluginManager.h" +#if PLATFORM_WINDOWS +#include "Windows/AllowWindowsPlatformTypes.h" +#include +#include +#include "Windows/HideWindowsPlatformTypes.h" +#endif #define LOCTEXT_NAMESPACE "FImmutableModule" @@ -22,11 +28,61 @@ void FImmutableModule::StartupModule() { #endif } -void FImmutableModule::ShutdownModule() { - // This code will execute after your module is loaded into memory; the exact - // timing is specified in the .uplugin file per-module This function may be - // called during shutdown to clean up your module. For modules that support - // dynamic reloading, we call this function before unloading the module. +void FImmutableModule::ShutdownModule() +{ +#if PLATFORM_WINDOWS && USING_BLUI_CEF + DWORD aProcesses[1024], cbNeeded; + unsigned int i; + + if (EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) + { + // Calculate how many process identifiers were returned. + DWORD cProcesses = cbNeeded / sizeof(DWORD); + + // Print the name and process identifier for each process. + for (i = 0; i < cProcesses; i++) + { + if (aProcesses[i] != 0) + { + TCHAR szProcessName[MAX_PATH] = TEXT(""); + // Get a handle to the process. + HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, aProcesses[i]); + DWORD errCode = GetLastError(); + + IMTBL_LOG("PID %d : ERROR %d ", aProcesses[i], errCode); + // Get the process name. + if (errCode == 0 && hProcess != NULL) + { + HMODULE hMod; + + cbNeeded = 0; + if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded)) + { + if (GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName) / sizeof(TCHAR))) + { + if (!_tcscmp(szProcessName, _T("blu_ue4_process.exe"))) + { + if (TerminateProcess(hProcess, 0) == 0) + { + IMTBL_ERR("Faild to shutdown BLUI executable process"); + } + else + { + IMTBL_LOG("BLUI executable process terminated"); + } + } + } + } + errCode = GetLastError(); + + // Release the handle to the process. + CloseHandle(hProcess); + } + } + } + } + +#endif } #undef LOCTEXT_NAMESPACE