From 51af3be468ae017e6697439be213ae2b7202faf5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 10 Dec 2019 14:40:07 -0800 Subject: [PATCH] Don't attempt to wait for session ending when it has already ended See https://github.com/immersive-web/webxr/pull/939 --- components/script/dom/xrsession.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 1ffe7ff77c3..bab52ab326f 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -540,6 +540,19 @@ impl XRSessionMethods for XRSession { fn End(&self) -> Rc { let global = self.global(); let p = Promise::new(&global); + if self.ended.get() && self.end_promises.borrow().is_empty() { + // If the session has completely ended and all end promises have been resolved, + // don't queue up more end promises + // + // We need to check for end_promises being empty because `ended` is set + // before everything has been completely shut down, and we do not want to + // prematurely resolve the promise then + // + // However, if end_promises is empty, then all end() promises have already resolved, + // so the session has completely shut down and we should not queue up more promises + p.resolve_native(&()); + return p; + } self.end_promises.borrow_mut().push(p.clone()); // This is duplicated in event_callback since this should // happen ASAP for end() but can happen later if the device