From f0e6133c246b5a4fe5f4c69b9d7b755581f41dcb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 3 Jun 2010 23:27:54 -0600 Subject: Add refcounts to textures and interiors. --- libdimension/texture.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'libdimension/texture.c') diff --git a/libdimension/texture.c b/libdimension/texture.c index 218b7f6..93279bb 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -80,9 +80,11 @@ dmnsn_texture * dmnsn_new_texture() { dmnsn_texture *texture = dmnsn_malloc(sizeof(dmnsn_texture)); - texture->pigment = NULL; - texture->finish = NULL; - texture->trans = dmnsn_identity_matrix(); + texture->pigment = NULL; + texture->finish = NULL; + texture->trans = dmnsn_identity_matrix(); + texture->refcount = dmnsn_malloc(sizeof(unsigned int)); + *texture->refcount = 1; return texture; } @@ -91,9 +93,14 @@ void dmnsn_delete_texture(dmnsn_texture *texture) { if (texture) { - dmnsn_delete_finish(texture->finish); - dmnsn_delete_pigment(texture->pigment); - free(texture); + if (*texture->refcount <= 1) { + dmnsn_delete_finish(texture->finish); + dmnsn_delete_pigment(texture->pigment); + free(texture->refcount); + free(texture); + } else { + --*texture->refcount; + } } } -- cgit v1.2.3