Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Correct ExternaVR shutdown. Fixes #538
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Sep 19, 2018
1 parent 34ab2af commit 096dc2e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ protected void onDestroy() {

SessionStore.get().clearListeners();
super.onDestroy();
// FIXME: HACK TO KILL GECKO BETWEEN RUNS.
android.os.Process.killProcess(android.os.Process.myPid());
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ void
BrowserWorld::ShutdownJava() {
ASSERT_ON_RENDER_THREAD();
VRB_LOG("BrowserWorld::ShutdownJava");
if (m.externalVR) {
m.externalVR->Shutdown();
}
GeckoSurfaceTexture::ShutdownJava();
VRBrowser::ShutdownJava();
if (m.env) {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,26 @@ ExternalVR::StopPresenting() {
m.waitingForExit = true;
}

void
ExternalVR::Shutdown() {
m.system.displayState.shutdown = true;
m.system.displayState.mSuppressFrames = true;
PushSystemState();

// Wait until Gecko has processed the shutdown message
// Otherwise the shmem data may be deallocated before Gecko processes it, leading to undefined behaviour
Wait wait(m.data.browserMutex, m.data.browserCond);
wait.Lock();
m.PullBrowserStateWhileLocked();
while (!m.data.browserState.shutdown) {
if (!wait.DoWait(0.1)) {
VRB_WARN("FXR Shutdown wait timeout");
break;
}
m.PullBrowserStateWhileLocked();
}
}

ExternalVR::ExternalVR(State& aState) : m(aState) {
PushSystemState();
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/ExternalVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ExternalVR : public ImmersiveDisplay {
const double aBottomDegrees) override;
void SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) override;
void SetEyeResolution(const int32_t aX, const int32_t aY) override;
void CompleteEnumeration() override;
// ExternalVR interface
void PushSystemState();
void PullBrowserState();
Expand All @@ -50,7 +51,7 @@ class ExternalVR : public ImmersiveDisplay {
bool WaitFrameResult();
void GetFrameResult(int32_t& aSurfaceHandle, device::EyeRect& aLeftEye, device::EyeRect& aRightEye) const;
void StopPresenting();
void CompleteEnumeration() override;
void Shutdown();
protected:
struct State;
ExternalVR(State& aState);
Expand Down

0 comments on commit 096dc2e

Please sign in to comment.