From aa748ef7e519243944bbf439562a9fc78cebd080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 2 Mar 2021 00:56:29 -0500 Subject: [PATCH] mesa: add assertions for buffer reference counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Zoltán Böszörményi Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/bufferobj.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index b2a36a34756..6a8c80bf535 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -514,6 +514,8 @@ _mesa_reference_buffer_object_(struct gl_context *ctx, /* Unreference the old buffer */ struct gl_buffer_object *oldObj = *ptr; + assert(oldObj->RefCount >= 1); + /* Count references only if the context doesn't own the buffer or if * ptr is a binding point shared by multiple contexts (such as a texture * buffer object being a buffer bound within a texture object). @@ -1700,6 +1702,11 @@ delete_buffers(struct gl_context *ctx, GLsizei n, const GLuint *ids) */ bufObj->DeletePending = GL_TRUE; + /* The GLuint ID holds one reference and the context that created + * the buffer holds the other one. + */ + assert(p_atomic_read(&bufObj->RefCount) >= (bufObj->Ctx ? 2 : 1)); + if (bufObj->Ctx == ctx) { detach_ctx_from_buffer(ctx, bufObj); } else if (bufObj->Ctx) {