Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DX-2591] fix: adjusted blui process closure routines #70

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions Source/Immutable/Private/Immutable/ImtblBlui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Source/Immutable/Private/Immutable/ImtblBlui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
66 changes: 61 additions & 5 deletions Source/Immutable/Private/ImmutableModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#include "Immutable/Misc/ImtblLogging.h"
#include "Interfaces/IPluginManager.h"
#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#include <windows.h>
#include <psapi.h>
#include "Windows/HideWindowsPlatformTypes.h"
#endif

#define LOCTEXT_NAMESPACE "FImmutableModule"

Expand All @@ -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.
wdinau marked this conversation as resolved.
Show resolved Hide resolved
void FImmutableModule::ShutdownModule()
YermekG marked this conversation as resolved.
Show resolved Hide resolved
{
#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("<unknown>");
// 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
Expand Down
Loading