Fix GrGpuBuffer::onRelease() crash problem.
The crash is because method GrGpuBuffer::onRelease() is called on wrong
thread. SkMessageBus::Post(const Message& m) takes a const ref of the
message, so there is a little possibility the GPU thread received and
handled the message before SkMessageBus::Post() is returned. In that
case, the caller of SkMessageBus::Post() (AsyncReadResult) still holds
the last ref of the GrGpuBuffer, and then GrGpuBuffer() will just be
released on the wrong thread.
Bug: chromium:1185489
Change-Id: I28665dbb1db7925d59ec574e9e26385e845ff4df
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380696
Commit-Queue: Peng Huang <penghuang@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Auto-Submit: Peng Huang <penghuang@chromium.org>
diff --git a/src/gpu/GrClientMappedBufferManager.h b/src/gpu/GrClientMappedBufferManager.h
index 3f3b067..20ef457 100644
--- a/src/gpu/GrClientMappedBufferManager.h
+++ b/src/gpu/GrClientMappedBufferManager.h
@@ -29,10 +29,17 @@
* Set fInboxID to inboxID(). fBuffer must have been previously passed to insert().
*/
struct BufferFinishedMessage {
+ BufferFinishedMessage(sk_sp<GrGpuBuffer> buffer, uint32_t indexId)
+ : fBuffer(std::move(buffer)), fInboxID(indexId) {}
+ BufferFinishedMessage(BufferFinishedMessage&& other) {
+ fBuffer = std::move(other.fBuffer);
+ fInboxID = other.fInboxID;
+ other.fInboxID = 0;
+ }
sk_sp<GrGpuBuffer> fBuffer;
uint32_t fInboxID;
};
- using BufferFinishedMessageBus = SkMessageBus<BufferFinishedMessage>;
+ using BufferFinishedMessageBus = SkMessageBus<BufferFinishedMessage, false>;
GrClientMappedBufferManager(uint32_t contextID);
GrClientMappedBufferManager(const GrClientMappedBufferManager&) = delete;