paint-volume: Do not take a reference on the actor

The paint volume structure is cached in the Actor it references, and
this causes a reference cycle.

The paint volume is going to be used when painting, so the actor must
still be valid - otherwise Clutter will bail out far before than
accessing the actor pointer in ClutterPaintVolume.

Otherwise, we could have used dispose() to check for a valid actor and
remove a reference if the actor field is !NULL; it feels less clean,
though, since we're effectively managing an extra reference on
ourselves.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2431
This commit is contained in:
Emmanuele Bassi 2010-11-18 10:53:01 +00:00
parent 0371ba3976
commit a94ea93bde
2 changed files with 6 additions and 20 deletions

View File

@ -2694,7 +2694,6 @@ clutter_actor_set_rotation_internal (ClutterActor *self,
{ {
ClutterActorPrivate *priv = self->priv; ClutterActorPrivate *priv = self->priv;
g_object_ref (self);
g_object_freeze_notify (G_OBJECT (self)); g_object_freeze_notify (G_OBJECT (self));
switch (axis) switch (axis)
@ -2716,7 +2715,6 @@ clutter_actor_set_rotation_internal (ClutterActor *self,
} }
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
g_object_unref (self);
clutter_actor_queue_redraw (self); clutter_actor_queue_redraw (self);
} }
@ -11692,7 +11690,7 @@ clutter_actor_get_transformed_paint_volume (ClutterActor *self,
return NULL; return NULL;
volume = clutter_actor_get_paint_volume (self); volume = clutter_actor_get_paint_volume (self);
if (!volume) if (volume == NULL)
return NULL; return NULL;
_clutter_actor_get_relative_modelview (self, relative_to_ancestor, &matrix); _clutter_actor_get_relative_modelview (self, relative_to_ancestor, &matrix);
@ -11702,8 +11700,8 @@ clutter_actor_get_transformed_paint_volume (ClutterActor *self,
_clutter_paint_volume_copy_static (volume, transformed_volume); _clutter_paint_volume_copy_static (volume, transformed_volume);
_clutter_paint_volume_transform (transformed_volume, &matrix); _clutter_paint_volume_transform (transformed_volume, &matrix);
_clutter_paint_volume_axis_align (transformed_volume); _clutter_paint_volume_axis_align (transformed_volume);
g_object_unref (transformed_volume->actor); _clutter_paint_volume_set_reference_actor (transformed_volume,
transformed_volume->actor = g_object_ref (relative_to_ancestor); relative_to_ancestor);
return transformed_volume; return transformed_volume;
} }

View File

@ -60,7 +60,7 @@ _clutter_paint_volume_new (ClutterActor *actor)
pv = g_slice_new (ClutterPaintVolume); pv = g_slice_new (ClutterPaintVolume);
pv->actor = g_object_ref (actor); pv->actor = actor;
memset (pv->vertices, 0, 8 * sizeof (ClutterVertex)); memset (pv->vertices, 0, 8 * sizeof (ClutterVertex));
@ -95,7 +95,7 @@ _clutter_paint_volume_init_static (ClutterActor *actor,
{ {
g_return_if_fail (actor != NULL); g_return_if_fail (actor != NULL);
pv->actor = g_object_ref (actor); pv->actor = actor;
memset (pv->vertices, 0, 8 * sizeof (ClutterVertex)); memset (pv->vertices, 0, 8 * sizeof (ClutterVertex));
@ -114,7 +114,6 @@ _clutter_paint_volume_copy_static (const ClutterPaintVolume *src_pv,
g_return_if_fail (src_pv != NULL && dst_pv != NULL); g_return_if_fail (src_pv != NULL && dst_pv != NULL);
memcpy (dst_pv, src_pv, sizeof (ClutterPaintVolume)); memcpy (dst_pv, src_pv, sizeof (ClutterPaintVolume));
g_object_ref (dst_pv->actor);
dst_pv->is_static = TRUE; dst_pv->is_static = TRUE;
} }
@ -136,9 +135,6 @@ clutter_paint_volume_copy (const ClutterPaintVolume *pv)
g_return_val_if_fail (pv != NULL, NULL); g_return_val_if_fail (pv != NULL, NULL);
copy = g_slice_dup (ClutterPaintVolume, pv); copy = g_slice_dup (ClutterPaintVolume, pv);
if (copy->actor)
g_object_ref (copy->actor);
copy->is_static = FALSE; copy->is_static = FALSE;
return copy; return copy;
@ -148,11 +144,6 @@ void
_clutter_paint_volume_set_from_volume (ClutterPaintVolume *pv, _clutter_paint_volume_set_from_volume (ClutterPaintVolume *pv,
const ClutterPaintVolume *src) const ClutterPaintVolume *src)
{ {
if (src->actor != pv->actor)
{
g_object_unref (pv->actor);
g_object_ref (src->actor);
}
memcpy (pv, src, sizeof (ClutterPaintVolume)); memcpy (pv, src, sizeof (ClutterPaintVolume));
} }
@ -169,8 +160,6 @@ clutter_paint_volume_free (ClutterPaintVolume *pv)
{ {
g_return_if_fail (pv != NULL); g_return_if_fail (pv != NULL);
g_object_unref (pv->actor);
if (G_LIKELY (pv->is_static)) if (G_LIKELY (pv->is_static))
return; return;
@ -918,6 +907,5 @@ _clutter_paint_volume_set_reference_actor (ClutterPaintVolume *pv,
{ {
g_return_if_fail (pv != NULL); g_return_if_fail (pv != NULL);
g_object_unref (pv->actor); pv->actor = actor;
pv->actor = g_object_ref (actor);
} }