Skip to content

Commit f5718ed

Browse files
committed
Add retry count to OpenXR init wait
Also show initialization errors in Windows message boxes.
1 parent e0b0330 commit f5718ed

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ set(HEADERS
3737
set(openRBRVR_Major 0)
3838
set(openRBRVR_Minor 5)
3939
set(openRBRVR_Patch 0)
40-
set(openRBRVR_Tweak 0)
41-
# set(openRBRVR_TweakStr "-beta${openRBRVR_Tweak}")
40+
set(openRBRVR_Tweak 2)
41+
set(openRBRVR_TweakStr "-rc${openRBRVR_Tweak}")
4242

4343
configure_file(
4444
${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in

OpenXR.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ void OpenXR::Init(IDirect3DDevice9* dev, const Config& cfg, IDirect3DVR9** vrdev
299299
.type = XR_TYPE_EVENT_DATA_BUFFER,
300300
.next = nullptr,
301301
};
302-
while (true) {
302+
auto retries = 10;
303+
while (retries-- > 0) {
303304
if (auto res = xrPollEvent(instance, &eventData); res == XR_SUCCESS) {
304305
if (eventData.type == XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED) {
305306
const XrEventDataSessionStateChanged* sessionStateChangedEvent = reinterpret_cast<const XrEventDataSessionStateChanged*>(&eventData);
@@ -314,12 +315,25 @@ void OpenXR::Init(IDirect3DDevice9* dev, const Config& cfg, IDirect3DVR9** vrdev
314315
if (auto res = xrBeginSession(session, &sessionBeginInfo); res != XR_SUCCESS) {
315316
throw std::runtime_error(std::format("Failed to initialize OpenXR. xrBeginSession: {}", XrResultToString(instance, res)));
316317
}
318+
317319
break;
318320
}
319321
}
320322
}
321323
}
322324

325+
if (retries == 0) {
326+
Dbg("Did not receive XR_SESSION_STATE_READY event, launching the session anyway...");
327+
XrSessionBeginInfo sessionBeginInfo = {
328+
.type = XR_TYPE_SESSION_BEGIN_INFO,
329+
.next = nullptr,
330+
.primaryViewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
331+
};
332+
if (auto res = xrBeginSession(session, &sessionBeginInfo); res != XR_SUCCESS) {
333+
throw std::runtime_error(std::format("Failed to initialize OpenXR. xrBeginSession: {}", XrResultToString(instance, res)));
334+
}
335+
}
336+
323337
eyePos[LeftEye] = glm::identity<glm::mat4x4>();
324338
eyePos[RightEye] = glm::identity<glm::mat4x4>();
325339
}

openRBRVR.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ HRESULT __stdcall DXHook_CreateDevice(
629629
hooks::drawindexedprimitive = Hook(devvtbl->DrawIndexedPrimitive, DXHook_DrawIndexedPrimitive);
630630
} catch (const std::runtime_error& e) {
631631
Dbg(e.what());
632+
MessageBoxA(hFocusWindow, e.what(), "Hooking failed", MB_OK);
632633
}
633634

634635
gD3Ddev = dev;
@@ -643,7 +644,7 @@ HRESULT __stdcall DXHook_CreateDevice(
643644
gVR = std::make_unique<OpenVR>(dev, gCfg, &gD3DVR, winBounds.right, winBounds.bottom);
644645
}
645646
} catch (const std::runtime_error& e) {
646-
Dbg(std::format("VR init failed: {}", e.what()));
647+
MessageBoxA(hFocusWindow, std::format("VR init failed: {}", e.what()).c_str(), "VR init failed", MB_OK);
647648
}
648649
// Initialize this pointer here, as it's too early to do this in openRBRVR constructor
649650
auto rxHandle = GetModuleHandle("Plugins\\rbr_rx.dll");
@@ -656,6 +657,7 @@ HRESULT __stdcall DXHook_CreateDevice(
656657
hooks::btbsetrendertarget = Hook(rbrrxdev->SetRenderTarget, BTB_SetRenderTarget);
657658
} catch (const std::runtime_error& e) {
658659
Dbg(e.what());
660+
MessageBoxA(hFocusWindow, e.what(), "Hooking failed", MB_OK);
659661
}
660662
}
661663

0 commit comments

Comments
 (0)