Commit e5023c2e authored by Bill Orr's avatar Bill Orr Committed by Commit Bot

Fix lifetime issues with OpenVR

There were a number of issues with lifetime that would cause issues,
such as multiple initializations of OpenVR, multiple conflicting
OpenVRDevices, and leaking objects.

This change fixes those so OpenVRDeviceProvider owns OpenVRDevice, which
owns OpenVRRenderLoop, and OpenVRRenderLoop correctly cleans up its bindings.

Change-Id: I32ee8abaa70a8a13155448e697d318c675f1d9ed
Reviewed-on: https://chromium-review.googlesource.com/777787Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Bill Orr <billorr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517649}
parent 531bf19b
......@@ -14,14 +14,24 @@ namespace device {
OpenVRDeviceProvider::OpenVRDeviceProvider()
: initialized_(false), vr_system_(nullptr) {}
OpenVRDeviceProvider::~OpenVRDeviceProvider() {}
OpenVRDeviceProvider::~OpenVRDeviceProvider() {
device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
device::GAMEPAD_SOURCE_OPENVR);
device_ = nullptr;
vr::VR_Shutdown();
}
void OpenVRDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) {
if (initialized_) {
VRDevice* device = new OpenVRDevice(vr_system_);
devices->push_back(device);
GamepadDataFetcherManager::GetInstance()->AddFactory(
new OpenVRGamepadDataFetcher::Factory(device->GetId(), vr_system_));
if (!device_) {
device_ = std::make_unique<OpenVRDevice>(vr_system_);
GamepadDataFetcherManager::GetInstance()->AddFactory(
new OpenVRGamepadDataFetcher::Factory(device_->GetId(), vr_system_));
}
if (device_) {
devices->push_back(device_.get());
}
}
}
......
......@@ -18,6 +18,8 @@ class IVRSystem;
namespace device {
class OpenVRDevice;
class DEVICE_VR_EXPORT OpenVRDeviceProvider : public VRDeviceProvider {
public:
OpenVRDeviceProvider();
......@@ -29,6 +31,7 @@ class DEVICE_VR_EXPORT OpenVRDeviceProvider : public VRDeviceProvider {
private:
bool initialized_;
vr::IVRSystem* vr_system_;
std::unique_ptr<OpenVRDevice> device_;
DISALLOW_COPY_AND_ASSIGN(OpenVRDeviceProvider);
};
......
......@@ -20,7 +20,9 @@ OpenVRRenderLoop::OpenVRRenderLoop()
DCHECK(main_thread_task_runner_);
}
OpenVRRenderLoop::~OpenVRRenderLoop() {}
OpenVRRenderLoop::~OpenVRRenderLoop() {
Stop();
}
void OpenVRRenderLoop::SubmitFrame(int16_t frame_index,
const gpu::MailboxHolder& mailbox) {
......@@ -78,6 +80,11 @@ void OpenVRRenderLoop::SubmitFrameWithTextureHandle(
#endif
}
void OpenVRRenderLoop::CleanUp() {
submit_client_ = nullptr;
binding_.Close();
}
void OpenVRRenderLoop::UpdateLayerBounds(int16_t frame_id,
const gfx::RectF& left_bounds,
const gfx::RectF& right_bounds,
......
......@@ -45,6 +45,7 @@ class OpenVRRenderLoop : public base::Thread, mojom::VRPresentationProvider {
private:
// base::Thread overrides:
void Init() override;
void CleanUp() override;
mojom::VRPosePtr GetPose();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment