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>
(cherry picked from commit 2eec9758f67e9073371c2edd63379324849373c4)
This commit is contained in:
Felix Riemann 2014-04-12 00:26:00 +02:00 committed by Neil Roberts
parent 22378d572b
commit 5556241b67

View File

@ -746,15 +746,25 @@ allocate_space (CoglAtlasTexture *atlas_tex,
/* Look for an existing atlas that can hold the texture */ /* Look for an existing atlas that can hold the texture */
for (l = ctx->atlases; l; l = l->next) 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, /* We need to take a reference on the atlas before trying to
/* Add two pixels for the border */ * reserve space because in some circumstances atlas migration
width + 2, height + 2, * can cause the atlas to be freed */
atlas_tex)) atlas = cogl_object_ref (l->data);
{ /* Try to make some space in the atlas for the texture */
cogl_object_ref (atlas); if (_cogl_atlas_reserve_space (atlas,
break; /* 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 we couldn't find a suitable atlas then start another */
if (l == NULL) if (l == NULL)