mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix a race in PlatformView construction (flutter/engine#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
This commit is contained in:
parent
21f38d7a48
commit
23a36caa6f
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user