Skip to content

Commit

Permalink
openxr: check 32-bit runtime; improve init errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Detegr committed Oct 25, 2024
1 parent dd256ab commit dff1127
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.5

- Add OpenXR runtime validation in initialization
- Improve OpenXR initialization error messages
- Fix invalid openRBRVR version number shown inside the game

## 1.0.4

- Fix a typo in predictionDampening setting
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(HEADERS

set(openRBRVR_Major 1)
set(openRBRVR_Minor 0)
set(openRBRVR_Patch 3)
set(openRBRVR_Patch 5)
set(openRBRVR_Tweak 0)
#set(openRBRVR_TweakStr "-rc${openRBRVR_Tweak}")

Expand Down
23 changes: 17 additions & 6 deletions src/OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,36 @@ OpenXR::OpenXR()
g::api_layer_search_path_fixed = true;
}

DWORD runtime_path_len = 0;
auto reg_err = RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Khronos\\OpenXR\\1", "ActiveRuntime", RRF_RT_REG_SZ, nullptr, nullptr, &runtime_path_len);
if (reg_err != ERROR_SUCCESS) {
if (reg_err == ERROR_FILE_NOT_FOUND) {
MessageBoxA(nullptr, "No 32-bit OpenXR runtime active.\nOpenXR initialization will likely fail.\nCheck the openRBRVR FAQ for runtime and device support.", "Error", MB_OK);
} else {
MessageBoxA(nullptr, std::format("Could not check the registry for runtime (error {}). OpenXR initialization may not succeed.", reg_err).c_str(), "Error", MB_OK);
}
} else if (runtime_path_len == 0) {
MessageBoxA(nullptr, "No 32-bit OpenXR runtime active.\nOpenXR initialization will likely fail.\nCheck the openRBRVR FAQ for runtime and device support.", "Error", MB_OK);
}

uint32_t api_layer_count;
if (auto err = xrEnumerateApiLayerProperties(0, &api_layer_count, nullptr); err != XR_SUCCESS) {
throw std::runtime_error(std::format("OpenXR: Failed to enumerate API layers, error: {}", static_cast<int>(err)));
throw std::runtime_error(std::format("OpenXR: Failed to enumerate API layers, error: {}", xr_result_to_str(err)));
}

std::vector<XrApiLayerProperties> available_api_layers(api_layer_count, { .type = XR_TYPE_API_LAYER_PROPERTIES });
if (auto err = xrEnumerateApiLayerProperties(api_layer_count, &api_layer_count, available_api_layers.data()); err != XR_SUCCESS) {
throw std::runtime_error(std::format("OpenXR: Failed to enumerate API layers, error: {}", static_cast<int>(err)));
throw std::runtime_error(std::format("OpenXR: Failed to enumerate API layers, error: {}", xr_result_to_str(err)));
}

uint32_t extension_count;
if (auto err = xrEnumerateInstanceExtensionProperties(nullptr, 0, &extension_count, nullptr); err != XR_SUCCESS) {
throw std::runtime_error(std::format("OpenXR: Failed to enumerate extension properties, error: {}", static_cast<int>(err)));
throw std::runtime_error(std::format("OpenXR: Failed to enumerate extension properties, error: {}", xr_result_to_str(err)));
}

std::vector<XrExtensionProperties> available_extensions(extension_count, { .type = XR_TYPE_EXTENSION_PROPERTIES });
if (auto err = xrEnumerateInstanceExtensionProperties(nullptr, extension_count, &extension_count, available_extensions.data()); err != XR_SUCCESS) {
throw std::runtime_error(std::format("OpenXR: Failed to enumerate extension properties, error: {}", static_cast<int>(err)));
throw std::runtime_error(std::format("OpenXR: Failed to enumerate extension properties, error: {}", xr_result_to_str(err)));
}

if (auto ext = std::ranges::find_if(available_extensions, [](const XrExtensionProperties& p) {
Expand Down Expand Up @@ -420,9 +432,8 @@ void OpenXR::init(IDirect3DDevice9* dev, IDirect3DVR9** vrdev, uint32_t companio
throw std::runtime_error(std::format("Failed to initialize OpenXR: xrCreateSession {}", XrResultToString(instance, err)));
}

XrViewConfigurationType view_config_types[] = { XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO };
uint32_t view_config_count;
if (auto err = xrEnumerateViewConfigurations(instance, system_id, 0, &view_config_count, view_config_types); err != XR_SUCCESS) {
if (auto err = xrEnumerateViewConfigurations(instance, system_id, 0, &view_config_count, nullptr); err != XR_SUCCESS) {
throw std::runtime_error("Failed to enumerate view configurations");
}
std::vector<XrViewConfigurationType> view_configs(view_config_count);
Expand Down

0 comments on commit dff1127

Please sign in to comment.