From 60d25b2e114b76cf815ca58d1dfdce7a7f3cce97 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 31 Oct 2017 01:49:45 -0700 Subject: [PATCH] Materials refcount their Textures properly; --- src/graphics/material.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/graphics/material.c b/src/graphics/material.c index a42d4e2d..0aa4d58a 100644 --- a/src/graphics/material.c +++ b/src/graphics/material.c @@ -42,5 +42,15 @@ Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType) } void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture) { - material->textures[textureType] = texture; + if (texture != material->textures[textureType]) { + if (material->textures[textureType]) { + lovrRelease(&material->textures[textureType]->ref); + } + + material->textures[textureType] = texture; + + if (texture) { + lovrRetain(&texture->ref); + } + } }