提交 2c5f028d 编写于 作者: J Jason Simmons 提交者: GitHub

Fix a race in PlatformView construction (#3380)

The PlatformView superclass constructor was posting a task to the UI thread
that adds the view to the shell's global list.  This could result in UI thread
operations seeing PlatformView instances that are not fully constructed and do
not yet have an engine.

This was happening in https://github.com/flutter/flutter/issues/7735
上级 2d54edf0
......@@ -18,10 +18,7 @@ namespace shell {
PlatformView::PlatformView(std::unique_ptr<Rasterizer> rasterizer)
: rasterizer_(std::move(rasterizer)),
size_(SkISize::Make(0, 0)),
weak_factory_(this) {
blink::Threads::UI()->PostTask(
[self = GetWeakPtr()] { Shell::Shared().AddPlatformView(self); });
}
weak_factory_(this) {}
PlatformView::~PlatformView() {
blink::Threads::UI()->PostTask([] { Shell::Shared().PurgePlatformViews(); });
......@@ -37,6 +34,13 @@ void PlatformView::CreateEngine() {
engine_.reset(new Engine(this));
}
// Add this to the shell's list of PlatformVIews.
// Subclasses should call this after the object is fully constructed.
void PlatformView::PostAddToShellTask() {
blink::Threads::UI()->PostTask(
[self = GetWeakPtr()] { Shell::Shared().AddPlatformView(self); });
}
void PlatformView::DispatchPlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) {
blink::Threads::UI()->PostTask(
......
......@@ -70,6 +70,7 @@ class PlatformView {
explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);
void CreateEngine();
void PostAddToShellTask();
void SetupResourceContextOnIOThreadPerform(
ftl::AutoResetWaitableEvent* event);
......
......@@ -104,6 +104,8 @@ PlatformViewAndroid::PlatformViewAndroid()
SetupResourceContextOnIOThread();
UpdateThreadPriorities();
PostAddToShellTask();
}
PlatformViewAndroid::~PlatformViewAndroid() = default;
......
......@@ -34,6 +34,8 @@ PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view)
shell::Shell::Shared().tracing_controller().set_traces_base_path(
[[paths objectAtIndex:0] UTF8String]);
}
PostAddToShellTask();
}
PlatformViewMac::~PlatformViewMac() = default;
......
......@@ -282,6 +282,8 @@ PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer)
NSUserDomainMask, YES);
shell::Shell::Shared().tracing_controller().set_traces_base_path(
[paths.firstObject UTF8String]);
PostAddToShellTask();
}
PlatformViewIOS::~PlatformViewIOS() = default;
......
......@@ -49,6 +49,8 @@ PlatformViewGLFW::PlatformViewGLFW()
});
valid_ = true;
PostAddToShellTask();
}
PlatformViewGLFW::~PlatformViewGLFW() {
......
......@@ -12,6 +12,7 @@ namespace shell {
PlatformViewTest::PlatformViewTest()
: PlatformView(std::unique_ptr<Rasterizer>(new NullRasterizer())) {
CreateEngine();
PostAddToShellTask();
}
PlatformViewTest::~PlatformViewTest() = default;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册