summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Riemann <friemann@gnome.org>2014-04-12 00:26:00 +0200
committerNeil Roberts <neil@linux.intel.com>2014-05-19 12:44:53 +0100
commit2eec9758f67e9073371c2edd63379324849373c4 (patch)
tree8a91901badfc0df2b822fe91326228976139a539
parent309bf866ca83664fe8b74f43d55ab7c83110b417 (diff)
downloadcogl-2eec9758f67e9073371c2edd63379324849373c4.tar.gz
atlas-texture: Keep reference on potential destination atlas
When a new CoglAtlasTexture tries to fit into an existing CoglAtlas it should make sure the atlas stays valid while it expands. https://bugzilla.gnome.org/show_bug.cgi?id=728064 Reviewed-by: Neil Roberts <neil@linux.intel.com>
-rw-r--r--cogl/cogl-atlas-texture.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index a812a004..0c44d2b0 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -740,15 +740,25 @@ allocate_space (CoglAtlasTexture *atlas_tex,
/* Look for an existing atlas that can hold the texture */
for (l = ctx->atlases; l; l = l->next)
- /* Try to make some space in the atlas for the texture */
- if (_cogl_atlas_reserve_space (atlas = l->data,
- /* Add two pixels for the border */
- width + 2, height + 2,
- atlas_tex))
- {
- cogl_object_ref (atlas);
- break;
- }
+ {
+ /* We need to take a reference on the atlas before trying to
+ * reserve space because in some circumstances atlas migration
+ * can cause the atlas to be freed */
+ atlas = cogl_object_ref (l->data);
+ /* Try to make some space in the atlas for the texture */
+ if (_cogl_atlas_reserve_space (atlas,
+ /* Add two pixels for the border */
+ width + 2, height + 2,
+ atlas_tex))
+ {
+ /* keep the atlas reference */
+ break;
+ }
+ else
+ {
+ cogl_object_unref (atlas);
+ }
+ }
/* If we couldn't find a suitable atlas then start another */
if (l == NULL)