From d014daaa536880789491a72f215dd38cf7d1fbaa Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 19 Nov 2016 14:21:17 -0800 Subject: [PATCH] Fix texture reference counting; --- src/graphics/texture.c | 10 +++++++--- src/graphics/texture.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/graphics/texture.c b/src/graphics/texture.c index 29086da7..01a7bc86 100644 --- a/src/graphics/texture.c +++ b/src/graphics/texture.c @@ -33,19 +33,23 @@ Texture* lovrTextureCreateFromBuffer(Buffer* buffer) { return NULL; } - Texture* texture = malloc(sizeof(Texture)); + Texture* texture = lovrAlloc(sizeof(Texture), lovrTextureDestroy); if (!texture) return NULL; glGenTextures(1, &texture->id); - texture->buffer = buffer->vbo; + texture->buffer = buffer; lovrTextureBind(texture); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, buffer->vbo); + lovrRetain(&buffer->ref); return texture; } void lovrTextureDestroy(const Ref* ref) { Texture* texture = containerof(ref, Texture); + if (texture->buffer) { + lovrRelease(&texture->buffer->ref); + } glDeleteTextures(1, &texture->id); free(texture); } @@ -60,7 +64,7 @@ void lovrTextureRefresh(Texture* texture) { } lovrTextureBind(texture); - glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, texture->buffer); + glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, texture->buffer->vbo); } int lovrTextureGetHeight(Texture* texture) { diff --git a/src/graphics/texture.h b/src/graphics/texture.h index fe9e812b..48a52e22 100644 --- a/src/graphics/texture.h +++ b/src/graphics/texture.h @@ -21,7 +21,7 @@ typedef enum { typedef struct { Ref ref; GLuint id; - GLuint buffer; + struct Buffer* buffer; int width; int height; FilterMode filterMin;