Skip to content

Commit

Permalink
Auto merge of #26312 - jdm:webxr-debug, r=Manishearth
Browse files Browse the repository at this point in the history
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 8c73fb9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/script/dom/xrsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
29 changes: 22 additions & 7 deletions ports/libsimpleservo/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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"))]
Expand Down
38 changes: 24 additions & 14 deletions support/hololens/ServoApp/ServoControl/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions support/hololens/ServoApp/ServoControl/ServoControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8c73fb9

Please sign in to comment.