summaryrefslogtreecommitdiffstats
path: root/libdimension/texture.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-06-03 23:27:54 -0600
committerTavian Barnes <tavianator@gmail.com>2010-06-03 23:27:54 -0600
commitf0e6133c246b5a4fe5f4c69b9d7b755581f41dcb (patch)
tree8a1bca3437bff3c16196e7065fccfa3e5add51c1 /libdimension/texture.c
parent8863129c6e7e57b7c4ca3fce5fece9aae8a9b7b7 (diff)
downloaddimension-f0e6133c246b5a4fe5f4c69b9d7b755581f41dcb.tar.xz
Add refcounts to textures and interiors.
Diffstat (limited to 'libdimension/texture.c')
-rw-r--r--libdimension/texture.c19
1 files changed, 13 insertions, 6 deletions
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;
+ }
}
}