summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-10-19 00:49:24 +0000
committerTavian Barnes <tavianator@gmail.com>2009-10-19 00:49:24 +0000
commit8710689500d3d35d04aabd727f12698590a816cb (patch)
tree02d69e8d47c584faff6b7b2622adb69699886078
parent19b06b1485a87a773d3f1ce897f6a00a22e6243d (diff)
downloaddimension-8710689500d3d35d04aabd727f12698590a816cb.tar.xz
Improve garbage handling of dmnsn_delete_object().
-rw-r--r--libdimension/object.c1
-rw-r--r--libdimension/texture.c5
-rw-r--r--tests/libdimension/tests.c14
3 files changed, 5 insertions, 15 deletions
diff --git a/libdimension/object.c b/libdimension/object.c
index f10d53d..18d7adb 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -57,6 +57,7 @@ void
dmnsn_delete_object(dmnsn_object *object)
{
if (object) {
+ dmnsn_delete_texture(object->texture);
if (object->free_fn) {
(*object->free_fn)(object->ptr);
}
diff --git a/libdimension/texture.c b/libdimension/texture.c
index f232cbc..a5ebd90 100644
--- a/libdimension/texture.c
+++ b/libdimension/texture.c
@@ -54,5 +54,8 @@ dmnsn_new_texture()
void
dmnsn_delete_texture(dmnsn_texture *texture)
{
- free(texture);
+ if (texture) {
+ dmnsn_delete_pigment(texture->pigment);
+ free(texture);
+ }
}
diff --git a/tests/libdimension/tests.c b/tests/libdimension/tests.c
index 12ff4e7..27876e4 100644
--- a/tests/libdimension/tests.c
+++ b/tests/libdimension/tests.c
@@ -94,7 +94,6 @@ dmnsn_new_default_scene()
sphere->texture->pigment = dmnsn_new_solid_pigment(dmnsn_white);
if (!sphere->texture->pigment) {
- dmnsn_delete_texture(sphere->texture);
dmnsn_delete_object(sphere);
dmnsn_delete_camera(scene->camera);
dmnsn_delete_canvas(scene->canvas);
@@ -109,8 +108,6 @@ dmnsn_new_default_scene()
cube = dmnsn_new_cube();
if (!cube) {
- dmnsn_delete_pigment(sphere->texture->pigment);
- dmnsn_delete_texture(sphere->texture);
dmnsn_delete_object(sphere);
dmnsn_delete_camera(scene->camera);
dmnsn_delete_canvas(scene->canvas);
@@ -121,8 +118,6 @@ dmnsn_new_default_scene()
cube->texture = dmnsn_new_texture();
if (!cube->texture) {
dmnsn_delete_object(cube);
- dmnsn_delete_pigment(sphere->texture->pigment);
- dmnsn_delete_texture(sphere->texture);
dmnsn_delete_object(sphere);
dmnsn_delete_camera(scene->camera);
dmnsn_delete_canvas(scene->canvas);
@@ -132,10 +127,7 @@ dmnsn_new_default_scene()
cube->texture->pigment = dmnsn_new_solid_pigment(dmnsn_black);
if (!cube->texture->pigment) {
- dmnsn_delete_texture(cube->texture);
dmnsn_delete_object(cube);
- dmnsn_delete_pigment(sphere->texture->pigment);
- dmnsn_delete_texture(sphere->texture);
dmnsn_delete_object(sphere);
dmnsn_delete_camera(scene->camera);
dmnsn_delete_canvas(scene->canvas);
@@ -158,14 +150,8 @@ dmnsn_delete_default_scene(dmnsn_scene *scene)
dmnsn_array_get(scene->objects, 0, &sphere);
dmnsn_array_get(scene->objects, 1, &cube);
- dmnsn_delete_pigment(cube->texture->pigment);
- dmnsn_delete_texture(cube->texture);
dmnsn_delete_object(cube);
-
- dmnsn_delete_pigment(sphere->texture->pigment);
- dmnsn_delete_texture(sphere->texture);
dmnsn_delete_object(sphere);
-
dmnsn_delete_camera(scene->camera);
dmnsn_delete_canvas(scene->canvas);
dmnsn_delete_scene(scene);