summaryrefslogtreecommitdiffstats
path: root/libdimension/texture.c
diff options
context:
space:
mode:
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;
+ }
}
}