summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-11-08 01:08:51 -0500
committerTavian Barnes <tavianator@gmail.com>2010-11-08 01:08:51 -0500
commit809c882062182afef2f68c4440194111ec4142ab (patch)
tree2de396a9ba8b26c22919855e69c69a5075a54a61 /libdimension
parenta9b0cc704a937015abba6094cdd14b1f2ecbb5e3 (diff)
downloaddimension-809c882062182afef2f68c4440194111ec4142ab.tar.xz
Fix double-init bug for inherited textures.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/texture.h1
-rw-r--r--libdimension/object.c13
-rw-r--r--libdimension/texture.c11
3 files changed, 18 insertions, 7 deletions
diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h
index 98e33b8..c30b368 100644
--- a/libdimension/dimension/texture.h
+++ b/libdimension/dimension/texture.h
@@ -107,6 +107,7 @@ typedef struct {
/* Reference count */
unsigned int *refcount;
+ bool should_init;
} dmnsn_texture;
dmnsn_texture *dmnsn_new_texture(void);
diff --git a/libdimension/object.c b/libdimension/object.c
index 873f5ee..d710304 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -57,6 +57,14 @@ dmnsn_delete_object(dmnsn_object *object)
void
dmnsn_object_init(dmnsn_object *object)
{
+ /* Don't double-init textures */
+ bool should_init = false;
+ dmnsn_matrix old_trans = object->trans;
+ if (object->texture) {
+ should_init = object->texture->should_init;
+ object->texture->should_init = false;
+ }
+
if (object->init_fn) {
(*object->init_fn)(object);
}
@@ -65,9 +73,10 @@ dmnsn_object_init(dmnsn_object *object)
= dmnsn_transform_bounding_box(object->trans, object->bounding_box);
object->trans_inv = dmnsn_matrix_inverse(object->trans);
- if (object->texture) {
+ if (should_init) {
+ /* Transform the texture with the object */
object->texture->trans
- = dmnsn_matrix_mul(object->trans, object->texture->trans);
+ = dmnsn_matrix_mul(old_trans, object->texture->trans);
dmnsn_texture_init(object->texture);
}
}
diff --git a/libdimension/texture.c b/libdimension/texture.c
index 7a012b5..9305f46 100644
--- a/libdimension/texture.c
+++ b/libdimension/texture.c
@@ -85,11 +85,12 @@ 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->refcount = dmnsn_malloc(sizeof(unsigned int));
- *texture->refcount = 1;
+ texture->pigment = NULL;
+ texture->finish = NULL;
+ texture->trans = dmnsn_identity_matrix();
+ texture->refcount = dmnsn_malloc(sizeof(unsigned int));
+ *texture->refcount = 1;
+ texture->should_init = true;
return texture;
}