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:
Carlo Bernaschina 2017-08-15 14:35:16 -07:00 committed by GitHub
parent 05dd4a01dd
commit e2b8d9e76b

View File

@ -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;
}
}