mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Avoid race condition into NotifyNextFrameOnce (flutter/engine#3980)
If GPURasterizer::NotifyNextFrameOnce was rapidly invoked twice could have lead to a null pointer exception. Also ftp::WeakPtr are not thread safe and should not be dereferenced from other threads.
This commit is contained in:
parent
05dd4a01dd
commit
e2b8d9e76b
@ -148,14 +148,11 @@ void GPURasterizer::AddNextFrameCallback(ftl::Closure nextFrameCallback) {
|
||||
|
||||
void GPURasterizer::NotifyNextFrameOnce() {
|
||||
if (nextFrameCallback_) {
|
||||
blink::Threads::Platform()->PostTask([weak_this = weak_factory_.GetWeakPtr()] {
|
||||
blink::Threads::Platform()->PostTask([callback = nextFrameCallback_] {
|
||||
TRACE_EVENT0("flutter", "GPURasterizer::NotifyNextFrameOnce");
|
||||
if (weak_this) {
|
||||
ftl::Closure callback = weak_this->nextFrameCallback_;
|
||||
callback();
|
||||
weak_this->nextFrameCallback_ = nullptr;
|
||||
}
|
||||
callback();
|
||||
});
|
||||
nextFrameCallback_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user