From 7fe0df393b905319a261258c68019c4edc29bcea Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 18 Sep 2010 08:41:52 +0100 Subject: [PATCH] texture: Add more validation on the material If set_cogl_texture() is called after unsetting the Texture's material then we really want to make a copy of the template. Also, we should assert more often if the internal state goes horribly wrong: at least, we'll have a backtrace. --- clutter/clutter-texture.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index 0a7a271da..afda05cb7 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -1271,6 +1271,7 @@ clutter_texture_init (ClutterTexture *self) cogl_handle_unref (dummy_tex); } + g_assert (texture_template_material != NULL); priv->material = cogl_material_copy (texture_template_material); } @@ -1356,13 +1357,16 @@ clutter_texture_set_cogl_material (ClutterTexture *texture, CoglHandle clutter_texture_get_cogl_texture (ClutterTexture *texture) { + ClutterTexturePrivate *priv; CoglMaterialLayerType layer_type; const GList *layers; int n_layers; g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), COGL_INVALID_HANDLE); - layers = cogl_material_get_layers (texture->priv->material); + priv = texture->priv; + + layers = cogl_material_get_layers (priv->material); if (layers == NULL) return COGL_INVALID_HANDLE; @@ -1421,6 +1425,10 @@ clutter_texture_set_cogl_texture (ClutterTexture *texture, texture_free_gl_resources (texture); /* Use the new texture */ + if (priv->material == NULL) + priv->material = cogl_material_copy (texture_template_material); + + g_assert (priv->material != NULL); cogl_material_set_layer (priv->material, 0, cogl_tex); /* The material now holds a reference to the texture so we can