Skip to content

Commit

Permalink
fix: fixed blui browser closure (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
YermekG authored Mar 12, 2024
1 parent ff34ed4 commit 11e8635
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 66 deletions.
9 changes: 6 additions & 3 deletions Source/Immutable/Private/Immutable/ImmutableSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ void UImmutableSubsystem::Initialize(FSubsystemCollectionBase& Collection)
void UImmutableSubsystem::Deinitialize()
{
IMTBL_LOG_FUNCSIG

BrowserWidget = nullptr;

#if USING_BLUI_CEF
IMTBL_LOG("Stopped BLUI event loop");
ImtblBlui->StopBluiEventLoop();
#endif
ImtblBlui->ConditionalBeginDestroy();
ImtblBlui = nullptr;
#endif

Passport = nullptr;

#if PLATFORM_ANDROID | PLATFORM_IOS
UGameViewportClient::OnViewportCreated().Remove(EngineInitCompleteHandle);
#else
Expand Down
15 changes: 8 additions & 7 deletions Source/Immutable/Private/Immutable/ImtblBlui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void UImtblBlui::OnLogEvent(const FString& LogText)
void UImtblBlui::WorldTickStart(UWorld* World, ELevelTick LevelTick, float X)
{
#if USING_BLUI_CEF
if (GetBluEye()->IsBrowserLoading()) {
IMTBL_LOG("Waiting for Browser to load...");
} else if (!bLoadedIndexJS) {
bLoadedIndexJS = true;
if (!GetBluEye()->IsBrowserLoading() && !bLoadedIndexJS) {
const FSoftObjectPath AssetRef(
TEXT("/Script/Immutable.ImtblSDKResource'/Immutable/PackagedResources/"
"index.index'"));
TEXT("/Script/Immutable.ImtblSDKResource'/Immutable/PackagedResources/"
"index.index'"));

IMTBL_LOG("Browser loaded");
bLoadedIndexJS = true;
if (UObject *LoadedAsset = AssetRef.TryLoad()) {
if (const auto Resource = Cast<UImtblSDKResource>(LoadedAsset)) {
GetBluEye()->ExecuteJS(Resource->Js);
Expand Down Expand Up @@ -136,14 +136,15 @@ void UImtblBlui::Init()
const FString CustomContentMethod(TEXT("X-GET-CUSTOM-CONTENT"));

const auto Request = CefRequest::Create();
Request->Set("file://Immutable/index.html", *CustomContentMethod,
Request->Set("file:///Immutable/index.html", *CustomContentMethod,
PostData, HeaderMap);

GetBluEye()->Browser->GetMainFrame()->LoadRequest(Request);
IMTBL_VERBOSE("LoadRequest'ed for Index.html")

WorldTickHandle = FWorldDelegates::OnWorldTickStart.AddUObject(
this, &UImtblBlui::WorldTickStart);
IMTBL_LOG("Waiting for Browser to load...");
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion Source/Immutable/Private/Immutable/ImtblBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void UImtblBrowserWidget::SetBrowserContent()
const FString IndexHtml = FString("<!doctype html><html lang='en'><head><meta " "charset='utf-8'><title>GameSDK Bridge</title><script>") + Resource->Js + FString("</script></head><body><h1>Bridge Running</h1></body></html>");

// IMTBL_LOG("Loaded resource: %s", *Resource->GetName())
WebBrowserWidget->LoadString(IndexHtml, TEXT("file://immutable/index.html"));
WebBrowserWidget->LoadString(IndexHtml, TEXT("file:///immutable/index.html"));
// WebBrowserWidget->LoadURL(FString::Printf(TEXT("%s%s"),
// TEXT("file:///"),
// *FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectContentDir(),
Expand Down
56 changes: 1 addition & 55 deletions Source/Immutable/Private/ImmutableModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,61 +30,7 @@ void FImmutableModule::StartupModule()
}

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("<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

0 comments on commit 11e8635

Please sign in to comment.