Skip to content
Permalink
Browse files
Auto merge of #26312 - jdm:webxr-debug, r=Manishearth
Provide feedback when OpenXR can't start

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26213
- [x] These changes do not require tests because it's testing an edge case in an environment we can't test on CI
  • Loading branch information
bors-servo committed Apr 25, 2020
2 parents b6a465c + a5970ab commit 8c73fb997a7320e9cf05184c6ad36c8c17da539a
Showing 5 changed files with 52 additions and 26 deletions.

Some generated files are not rendered by default. Learn more.

@@ -267,7 +267,8 @@ impl XRSystem {
) {
let session = match response {
Ok(session) => session,
Err(_) => {
Err(e) => {
warn!("Error requesting XR session: {:?}", e);
if mode != XRSessionMode::Inline {
self.pending_immersive_session.set(false);
}
@@ -810,7 +810,7 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
}

struct GlThread(WebGlExecutor);
impl webxr::openxr::GlThread for GlThread {
impl openxr::GlThread for GlThread {
fn execute(&self, runnable: Box<dyn FnOnce(&surfman::Device) + Send>) {
let _ = self.0.send(runnable);
}
@@ -819,12 +819,27 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
}
}

let discovery = webxr::openxr::OpenXrDiscovery::new(
Box::new(GlThread(executor)),
Box::new(ProviderRegistration(surface_providers)),
Box::new(ContextMenuCallback(embedder_proxy)),
);
registry.register(discovery);
if openxr::create_instance().is_ok() {
let discovery = openxr::OpenXrDiscovery::new(
Box::new(GlThread(executor)),
Box::new(ProviderRegistration(surface_providers)),
Box::new(ContextMenuCallback(embedder_proxy)),
);
registry.register(discovery);
} else {
let msg =
"Cannot initialize OpenXR - please ensure runtime is installed and enabled in \
the OpenXR developer portal app.\n\nImmersive mode will not function until \
this error is fixed.";
let (sender, _receiver) = ipc::channel().unwrap();
embedder_proxy.send((
None,
EmbedderMsg::Prompt(
PromptDefinition::Alert(msg.to_owned(), sender),
PromptOrigin::Trusted,
),
));
}
}

#[cfg(not(feature = "uwp"))]
@@ -161,21 +161,31 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,

sServo = this; // FIXME;

#ifdef _DEBUG
auto current = winrt::Windows::Storage::ApplicationData::Current();
auto filePath = std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt";
sLogHandle =
CreateFile2(filePath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr);
if (sLogHandle == INVALID_HANDLE_VALUE)
throw std::runtime_error("Failed to open the log file: error code " +
std::to_string(GetLastError()));

if (SetFilePointer(sLogHandle, 0, nullptr, FILE_END) ==
INVALID_SET_FILE_POINTER)
throw std::runtime_error(
"Failed to set file pointer to the end of file: error code " +
std::to_string(GetLastError()));
#ifndef _DEBUG
char buffer[1024];
bool logToFile = GetEnvironmentVariableA("FirefoxRealityLogStdout", buffer,
sizeof(buffer)) != 0;
#else
bool logToFile = true;
#endif
if (logToFile) {
auto current = winrt::Windows::Storage::ApplicationData::Current();
auto filePath =
std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt";
sLogHandle =
CreateFile2(filePath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr);
if (sLogHandle == INVALID_HANDLE_VALUE) {
throw std::runtime_error("Failed to open the log file: error code " +
std::to_string(GetLastError()));
}

if (SetFilePointer(sLogHandle, 0, nullptr, FILE_END) ==
INVALID_SET_FILE_POINTER) {
throw std::runtime_error(
"Failed to set file pointer to the end of file: error code " +
std::to_string(GetLastError()));
}
}

capi::CHostCallbacks c;
c.on_load_started = &on_load_started;
@@ -453,10 +453,10 @@ ServoControl::PromptSync(hstring title, hstring message, hstring primaryButton,
dialog.PrimaryButtonText(primaryButton);

if (secondaryButton.has_value()) {
dialog.IsPrimaryButtonEnabled(true);
dialog.IsSecondaryButtonEnabled(true);
dialog.SecondaryButtonText(*secondaryButton);
} else {
dialog.IsPrimaryButtonEnabled(false);
dialog.IsSecondaryButtonEnabled(false);
}

auto titleBlock = Controls::TextBlock();

0 comments on commit 8c73fb9

Please sign in to comment.