From 2cc32ca803d0749dc94ad3ddeb5ab9f4e5561bff Mon Sep 17 00:00:00 2001 From: Toan Pham Date: Tue, 14 Sep 2021 10:17:34 -0700 Subject: [PATCH] Fix Camera3D crash with preload When preloading, the initial Camera3D that was created does not have an associated impl() (i.e. an input::Camera3D) because an input manager is not instantiated in preload. This change allows graceful transition from the placeholder dom::Camera3D without input to a dom::Camera3D with input. b/198526160 Change-Id: Ib65355a4205c971f37c5499b599dc877975acadc (cherry picked from commit 9cb5d4454339405ff6beff41040479f087db0051) --- cobalt/dom/window.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cobalt/dom/window.cc b/cobalt/dom/window.cc index f83a7ead94d0..6fde6ea3b175 100644 --- a/cobalt/dom/window.cc +++ b/cobalt/dom/window.cc @@ -630,9 +630,11 @@ void Window::SetSize(ViewportSize size) { } void Window::UpdateCamera3D(const scoped_refptr& camera_3d) { - if (camera_3d_) { + if (camera_3d_ && camera_3d_->impl()) { + // Update input object for existing camera. camera_3d_->impl()->SetInput(camera_3d); } else { + // Create a new camera which uses the given input camera object. camera_3d_ = new Camera3D(camera_3d); camera_3d_->StartOrientationEvents(base::AsWeakPtr(this)); }