From 363a148ca84fb7886fa8abafdb14ebcbfba782b8 Mon Sep 17 00:00:00 2001 From: YermekG Date: Mon, 12 Feb 2024 16:40:44 +1300 Subject: [PATCH] fix: added fix to force blui process closure chore: adjusted code style fix: stop blui event loop on exit chore: added blui macro condition Revert "chore: adjusted code style" This reverts commit 40973e8b29868c9240069c15775b26ebbc2e7a53. # Conflicts: # Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp --- .../Private/Immutable/ImmutableSubsystem.cpp | 13 ++-- .../Immutable/Private/Immutable/ImtblBlui.cpp | 10 +++ .../Immutable/Private/Immutable/ImtblBlui.h | 4 ++ Source/Immutable/Private/ImmutableModule.cpp | 66 +++++++++++++++++-- 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp b/Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp index e1b93ee..d07eab4 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 ffe0377..b479428 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 2b2d047..47a1ee6 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 21f9b28..aed6b79 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