diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-08 01:08:51 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-08 01:08:51 -0500 |
commit | 809c882062182afef2f68c4440194111ec4142ab (patch) | |
tree | 2de396a9ba8b26c22919855e69c69a5075a54a61 /libdimension | |
parent | a9b0cc704a937015abba6094cdd14b1f2ecbb5e3 (diff) | |
download | dimension-809c882062182afef2f68c4440194111ec4142ab.tar.xz |
Fix double-init bug for inherited textures.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/texture.h | 1 | ||||
-rw-r--r-- | libdimension/object.c | 13 | ||||
-rw-r--r-- | libdimension/texture.c | 11 |
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; } |