[Transitions] Add error checking when setting up framebuffers

The framebuffer setup code can fail, e.g. when the texture used as
color buffer has a height/width of 0. In that case, the call to
cogl_pop_framebuffer() will crash the shell trigger an assert. Add
error checking to fail gracefully.
This commit is contained in:
Florian Müllner 2010-06-12 18:54:08 +02:00
parent a691192ffa
commit c0134067d7

View File

@ -198,7 +198,7 @@ calculate_offscreen_box (StThemeNodeTransition *transition,
- allocation->y1; - allocation->y1;
} }
static void static gboolean
setup_framebuffers (StThemeNodeTransition *transition, setup_framebuffers (StThemeNodeTransition *transition,
const ClutterActorBox *allocation, const ClutterActorBox *allocation,
guint8 paint_opacity) guint8 paint_opacity)
@ -210,6 +210,9 @@ setup_framebuffers (StThemeNodeTransition *transition,
width = priv->offscreen_box.x2 - priv->offscreen_box.x1; width = priv->offscreen_box.x2 - priv->offscreen_box.x1;
height = priv->offscreen_box.y2 - priv->offscreen_box.y1; height = priv->offscreen_box.y2 - priv->offscreen_box.y1;
g_return_val_if_fail (width > 0, FALSE);
g_return_val_if_fail (height > 0, FALSE);
if (priv->old_texture) if (priv->old_texture)
cogl_handle_unref (priv->old_texture); cogl_handle_unref (priv->old_texture);
priv->old_texture = cogl_texture_new_with_size (width, height, priv->old_texture = cogl_texture_new_with_size (width, height,
@ -222,6 +225,9 @@ setup_framebuffers (StThemeNodeTransition *transition,
COGL_TEXTURE_NO_SLICING, COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY); COGL_PIXEL_FORMAT_ANY);
g_return_val_if_fail (priv->old_texture != COGL_INVALID_HANDLE, FALSE);
g_return_val_if_fail (priv->new_texture != COGL_INVALID_HANDLE, FALSE);
if (priv->old_offscreen) if (priv->old_offscreen)
cogl_handle_unref (priv->old_offscreen); cogl_handle_unref (priv->old_offscreen);
priv->old_offscreen = cogl_offscreen_new_to_texture (priv->old_texture); priv->old_offscreen = cogl_offscreen_new_to_texture (priv->old_texture);
@ -230,6 +236,9 @@ setup_framebuffers (StThemeNodeTransition *transition,
cogl_handle_unref (priv->new_offscreen); cogl_handle_unref (priv->new_offscreen);
priv->new_offscreen = cogl_offscreen_new_to_texture (priv->new_texture); priv->new_offscreen = cogl_offscreen_new_to_texture (priv->new_texture);
g_return_val_if_fail (priv->old_offscreen != COGL_INVALID_HANDLE, FALSE);
g_return_val_if_fail (priv->new_offscreen != COGL_INVALID_HANDLE, FALSE);
if (priv->material) if (priv->material)
cogl_handle_unref (priv->material); cogl_handle_unref (priv->material);
priv->material = cogl_material_new (); priv->material = cogl_material_new ();
@ -262,6 +271,8 @@ setup_framebuffers (StThemeNodeTransition *transition,
allocation, allocation,
paint_opacity); paint_opacity);
cogl_pop_framebuffer (); cogl_pop_framebuffer ();
return TRUE;
} }
void void
@ -291,9 +302,9 @@ st_theme_node_transition_paint (StThemeNodeTransition *transition,
priv->last_opacity = paint_opacity; priv->last_opacity = paint_opacity;
calculate_offscreen_box (transition, allocation); calculate_offscreen_box (transition, allocation);
setup_framebuffers (transition, allocation, paint_opacity); priv->needs_setup = !setup_framebuffers (transition,
allocation,
priv->needs_setup = FALSE; paint_opacity);
} }
width = cogl_texture_get_width (priv->old_texture); width = cogl_texture_get_width (priv->old_texture);