* evas: Fix SEGV when smart object's child come from another layer than
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 15 Jun 2009 14:25:21 +0000 (14:25 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 15 Jun 2009 14:25:21 +0000 (14:25 +0000)
the parent.

When we insert object inside a smart object, they could be attached to
another layer. As long as ref counting work, nothing wrong will happen.
But during destruction of an Evas, we were just looping over all layers,
destroying each of them, without checking for refcounting. This could
cause SEGV.
      This patch introduce a third loop for wiping out all layers after
destroying all Evas_Object. So no more SEGV, and no performance
regression.

Note: Do not rely on evas_object_layer_get on smart object's child, it
could give you the wrong answer.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@41046 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/canvas/evas_layer.c
src/lib/canvas/evas_main.c
src/lib/include/evas_private.h

index da15d54..241de45 100644 (file)
@@ -71,7 +71,19 @@ evas_layer_free(Evas_Layer *lay)
        obj = (Evas_Object *)lay->objects;
        evas_object_free(obj, 0);
      }
-   free(lay);
+}
+
+void
+evas_layer_clean(Evas *e)
+{
+   Evas_Layer *tmp;
+
+   while (e->layers)
+     {
+       tmp = e->layers;
+       evas_layer_del(tmp);
+       free(tmp);
+     }
 }
 
 Evas_Layer *
@@ -122,6 +134,9 @@ evas_layer_del(Evas_Layer *lay)
 
 /**
  * Sets the layer of the evas that the given object will be part of.
+ *
+ * It is not possible to change the layer of a smart object's child.
+ *
  * @param   obj The given evas object.
  * @param   l   The number of the layer to place the object on.
  */
@@ -170,6 +185,11 @@ evas_object_layer_set(Evas_Object *obj, short l)
 
 /**
  * Retrieves the layer of the evas that the given object is part of.
+ *
+ * Be carefull, it doesn't make sense to change the layer of smart object's
+ * child. So the returned value could be wrong in some case. Don't rely on
+ * it's accuracy.
+ *
  * @param   obj The given evas object.
  * @return  Number of the layer.
  */
index 2d2065b..8e07c54 100644 (file)
@@ -158,12 +158,10 @@ evas_free(Evas *e)
               }
          }
      }
-   while (e->layers)
-     {
-       lay = e->layers;
-       evas_layer_del(lay);
-       evas_layer_free(lay);
-     }
+   EINA_INLIST_FOREACH(e->layers, lay)
+     evas_layer_free(lay);
+   evas_layer_clean(e);
+
    e->walking_list--;
 
    evas_font_path_clear(e);
index 7304966..87e9134 100644 (file)
@@ -718,6 +718,7 @@ void evas_object_recalc_clippees(Evas_Object *obj);
 Evas_Layer *evas_layer_new(Evas *e);
 void evas_layer_pre_free(Evas_Layer *lay);
 void evas_layer_free(Evas_Layer *lay);
+void evas_layer_clean(Evas *e);
 Evas_Layer *evas_layer_find(Evas *e, short layer_num);
 void evas_layer_add(Evas_Layer *lay);
 void evas_layer_del(Evas_Layer *lay);