Skip to content

Commit 7350715

Browse files
committed
Miscellaneous Windows AppRuntime fixes
1 parent df246e2 commit 7350715

File tree

3 files changed

+17
-32
lines changed

3 files changed

+17
-32
lines changed

Core/AppRuntime/Source/AppRuntime_Chakra.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,21 @@ namespace Babylon
2020

2121
void AppRuntime::RunEnvironmentTier(const char*)
2222
{
23-
using DispatchFunction = std::function<void(std::function<void()>)>;
24-
DispatchFunction dispatchFunction{
25-
[this](std::function<void()> action) {
26-
Dispatch([action = std::move(action)](Napi::Env) {
27-
action();
28-
});
29-
}};
30-
3123
JsRuntimeHandle jsRuntime;
3224
ThrowIfFailed(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &jsRuntime));
3325
JsContextRef context;
3426
ThrowIfFailed(JsCreateContext(jsRuntime, &context));
3527
ThrowIfFailed(JsSetCurrentContext(context));
3628
ThrowIfFailed(JsSetPromiseContinuationCallback([](JsValueRef task, void* callbackState) {
29+
auto* pThis = reinterpret_cast<AppRuntime*>(callbackState);
3730
ThrowIfFailed(JsAddRef(task, nullptr));
38-
auto* dispatch = reinterpret_cast<DispatchFunction*>(callbackState);
39-
dispatch->operator()([task]() {
40-
JsValueRef undefined;
41-
ThrowIfFailed(JsGetUndefinedValue(&undefined));
42-
ThrowIfFailed(JsCallFunction(task, &undefined, 1, nullptr));
31+
pThis->Dispatch([task](auto) {
32+
JsValueRef global;
33+
ThrowIfFailed(JsGetGlobalObject(&global));
34+
ThrowIfFailed(JsCallFunction(task, &global, 1, nullptr));
4335
ThrowIfFailed(JsRelease(task, nullptr));
4436
});
45-
},
46-
&dispatchFunction));
37+
}, this));
4738
ThrowIfFailed(JsProjectWinRTNamespace(L"Windows"));
4839

4940
#if defined(_DEBUG)

Core/AppRuntime/Source/AppRuntime_Win32.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "AppRuntime.h"
22

3-
#include <Objbase.h>
4-
#include <Windows.h>
3+
#include <winrt/base.h>
4+
#include <roapi.h>
55

66
#include <gsl/gsl>
77
#include <cassert>
@@ -10,23 +10,14 @@
1010

1111
namespace Babylon
1212
{
13-
namespace
14-
{
15-
constexpr size_t FILENAME_BUFFER_SIZE = 1024;
16-
}
17-
1813
void AppRuntime::RunPlatformTier()
1914
{
20-
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
21-
assert(SUCCEEDED(hr));
22-
_CRT_UNUSED(hr);
23-
auto coInitScopeGuard = gsl::finally([] { CoUninitialize(); });
15+
winrt::check_hresult(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED));
16+
17+
char executablePath[1024];
18+
winrt::check_win32(GetModuleFileNameA(nullptr, executablePath, ARRAYSIZE(executablePath)));
2419

25-
char filename[FILENAME_BUFFER_SIZE];
26-
auto result = GetModuleFileNameA(nullptr, filename, static_cast<DWORD>(std::size(filename)));
27-
assert(result != 0);
28-
(void)result;
29-
RunEnvironmentTier(filename);
20+
RunEnvironmentTier(executablePath);
3021
}
3122

3223
void AppRuntime::DefaultUnhandledExceptionHandler(const std::exception& error)

Core/AppRuntime/Source/AppRuntime_WinRT.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "AppRuntime.h"
22

3-
#include <Windows.h>
3+
#include <winrt/base.h>
4+
#include <roapi.h>
45

56
#include <exception>
67
#include <sstream>
@@ -9,6 +10,8 @@ namespace Babylon
910
{
1011
void AppRuntime::RunPlatformTier()
1112
{
13+
winrt::check_hresult(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED));
14+
1215
RunEnvironmentTier();
1316
}
1417

0 commit comments

Comments
 (0)