Commit b684d978 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[CRD iOS] Fixed a thread safety bug in GlDisplayHandler

GlDisplayHandlerCore::Initialize is posted before the Core's construction
is done, so the app may crash at some point due to race condition.

It crashed once in my phone when calling renderer_proxy_->Initialize()
while renderer_proxy_ is not ready.

Change-Id: If711b56efce2de5f7e4d0a7a883f19b2181ee31e
Reviewed-on: https://chromium-review.googlesource.com/597317Reviewed-by: default avatarScott Nichols <nicholss@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491445}
parent 9344ba0c
......@@ -61,6 +61,8 @@ class Core : public protocol::CursorShapeStub, public GlRendererDelegate {
void SurfaceChanged(int width, int height);
std::unique_ptr<protocol::FrameConsumer> GrabFrameConsumer();
// Returns a weak pointer to be used on the display thread.
base::WeakPtr<Core> GetWeakPtr();
private:
......@@ -93,9 +95,6 @@ Core::Core() : weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
runtime_->display_task_runner()->PostTask(
FROM_HERE, base::Bind(&Core::Initialize, base::Unretained(this)));
// Do not bind GlRenderer::OnFrameReceived. |renderer_| is not ready yet.
owned_frame_consumer_.reset(new remoting::DualBufferFrameConsumer(
base::Bind(&Core::OnFrameReceived, weak_ptr_),
......@@ -106,6 +105,9 @@ Core::Core() : weak_factory_(this) {
owned_renderer_proxy_.reset(
new RendererProxy(runtime_->display_task_runner()));
renderer_proxy_ = owned_renderer_proxy_->GetWeakPtr();
runtime_->display_task_runner()->PostTask(
FROM_HERE, base::Bind(&Core::Initialize, GetWeakPtr()));
}
Core::~Core() {
......
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