Skip to content

Commit 7490c1c

Browse files
authored
fix: added fix to force blui process closure (#70)
chore: adjusted code style fix: stop blui event loop on exit chore: added blui macro condition Revert "chore: adjusted code style" This reverts commit 40973e8. # Conflicts: # Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp
1 parent a4dce63 commit 7490c1c

File tree

4 files changed

+83
-10
lines changed

4 files changed

+83
-10
lines changed

Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ void UImmutableSubsystem::Initialize(FSubsystemCollectionBase &Collection) {
3434
this, &UImmutableSubsystem::WorldTickStart);
3535
}
3636

37-
void UImmutableSubsystem::Deinitialize() {
38-
IMTBL_LOG_FUNCSIG
39-
BrowserWidget = nullptr;
40-
ImtblBlui = nullptr;
41-
Passport = nullptr;
37+
void UImmutableSubsystem::Deinitialize()
38+
{
39+
IMTBL_LOG_FUNCSIG
40+
BrowserWidget = nullptr;
41+
IMTBL_LOG("Stopped BLUI event loop");
42+
ImtblBlui->StopBluiEventLoop();
43+
ImtblBlui = nullptr;
44+
Passport = nullptr;
4245
#if PLATFORM_ANDROID | PLATFORM_IOS
4346
UGameViewportClient::OnViewportCreated().Remove(EngineInitCompleteHandle);
4447
#else

Source/Immutable/Private/Immutable/ImtblBlui.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,13 @@ void UImtblBlui::Init() {
150150
JSConnector->Init(!BluEye->IsBrowserLoading());
151151
#endif
152152
}
153+
154+
#if USING_BLUI_CEF
155+
void UImtblBlui::StopBluiEventLoop()
156+
{
157+
if (UBluEye* BluEye = GetBluEye())
158+
{
159+
BluEye->SetShouldTickEventLoop(false);
160+
}
161+
}
162+
#endif

Source/Immutable/Private/Immutable/ImtblBlui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class IMMUTABLE_API UImtblBlui : public UObject {
2828
void BeginDestroy() override;
2929
void Init();
3030

31+
#if USING_BLUI_CEF
32+
void StopBluiEventLoop();
33+
#endif
34+
3135
private:
3236
UPROPERTY()
3337
UObject *BluEyePtr = nullptr;

Source/Immutable/Private/ImmutableModule.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#include "Immutable/Misc/ImtblLogging.h"
66
#include "Interfaces/IPluginManager.h"
7+
#if PLATFORM_WINDOWS
8+
#include "Windows/AllowWindowsPlatformTypes.h"
9+
#include <windows.h>
10+
#include <psapi.h>
11+
#include "Windows/HideWindowsPlatformTypes.h"
12+
#endif
713

814
#define LOCTEXT_NAMESPACE "FImmutableModule"
915

@@ -22,11 +28,61 @@ void FImmutableModule::StartupModule() {
2228
#endif
2329
}
2430

25-
void FImmutableModule::ShutdownModule() {
26-
// This code will execute after your module is loaded into memory; the exact
27-
// timing is specified in the .uplugin file per-module This function may be
28-
// called during shutdown to clean up your module. For modules that support
29-
// dynamic reloading, we call this function before unloading the module.
31+
void FImmutableModule::ShutdownModule()
32+
{
33+
#if PLATFORM_WINDOWS && USING_BLUI_CEF
34+
DWORD aProcesses[1024], cbNeeded;
35+
unsigned int i;
36+
37+
if (EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
38+
{
39+
// Calculate how many process identifiers were returned.
40+
DWORD cProcesses = cbNeeded / sizeof(DWORD);
41+
42+
// Print the name and process identifier for each process.
43+
for (i = 0; i < cProcesses; i++)
44+
{
45+
if (aProcesses[i] != 0)
46+
{
47+
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
48+
// Get a handle to the process.
49+
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, aProcesses[i]);
50+
DWORD errCode = GetLastError();
51+
52+
IMTBL_LOG("PID %d : ERROR %d ", aProcesses[i], errCode);
53+
// Get the process name.
54+
if (errCode == 0 && hProcess != NULL)
55+
{
56+
HMODULE hMod;
57+
58+
cbNeeded = 0;
59+
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
60+
{
61+
if (GetModuleBaseName(hProcess, hMod, szProcessName, sizeof(szProcessName) / sizeof(TCHAR)))
62+
{
63+
if (!_tcscmp(szProcessName, _T("blu_ue4_process.exe")))
64+
{
65+
if (TerminateProcess(hProcess, 0) == 0)
66+
{
67+
IMTBL_ERR("Faild to shutdown BLUI executable process");
68+
}
69+
else
70+
{
71+
IMTBL_LOG("BLUI executable process terminated");
72+
}
73+
}
74+
}
75+
}
76+
errCode = GetLastError();
77+
78+
// Release the handle to the process.
79+
CloseHandle(hProcess);
80+
}
81+
}
82+
}
83+
}
84+
85+
#endif
3086
}
3187

3288
#undef LOCTEXT_NAMESPACE

0 commit comments

Comments
 (0)