oooh thank you valgrind! found some bad mem access stuff in the gl
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 13 Jan 2011 10:41:08 +0000 (10:41 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 13 Jan 2011 10:41:08 +0000 (10:41 +0000)
engine on shutdown. was freeing the wring kind of thing in the first
place.. and even then it should be more robust, so fix gl texture
robustness and this bug. can cause on-exit crashes if not fixed.

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

src/modules/engines/gl_common/evas_gl_common.h
src/modules/engines/gl_common/evas_gl_context.c
src/modules/engines/gl_common/evas_gl_texture.c

index 5c9d8ed..864c33b 100644 (file)
@@ -448,6 +448,7 @@ void              evas_gl_common_shader_program_shutdown(Evas_GL_Program *p);
     
 void              evas_gl_common_rect_draw(Evas_GL_Context *gc, int x, int y, int w, int h);
 
+void              evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt);
 Evas_GL_Texture  *evas_gl_common_texture_new(Evas_GL_Context *gc, RGBA_Image *im);
 Evas_GL_Texture  *evas_gl_common_texture_native_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_GL_Image *im);
 Evas_GL_Texture  *evas_gl_common_texture_render_new(Evas_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
index 1a45cf0..b046841 100644 (file)
@@ -758,6 +758,7 @@ void
 evas_gl_common_context_free(Evas_GL_Context *gc)
 {
    int i, j;
+   Eina_List *l;
    
    gc->references--;
    if (gc->references > 0) return;
@@ -779,6 +780,8 @@ evas_gl_common_context_free(Evas_GL_Context *gc)
    
    if ((gc->shared) && (gc->shared->references == 0))
      {
+        Evas_GL_Texture_Pool *pt;
+        
         evas_gl_common_shader_program_shutdown(&(gc->shared->shader.rect));
         evas_gl_common_shader_program_shutdown(&(gc->shared->shader.font));
         evas_gl_common_shader_program_shutdown(&(gc->shared->shader.img));
@@ -794,20 +797,15 @@ evas_gl_common_context_free(Evas_GL_Context *gc)
           {
              evas_gl_common_image_free(gc->shared->images->data);
           }
-        while (gc->shared->tex.whole)
-          {
-             evas_gl_common_texture_free(gc->shared->tex.whole->data);
-          }
+        
+        EINA_LIST_FOREACH(gc->shared->tex.whole, l, pt)
+           evas_gl_texture_pool_empty(pt);
         for (i = 0; i < 33; i++)
           {
              for (j = 0; j < 3; j++)
                {
-                  while (gc->shared->tex.atlas[i][j])
-                    {
-                       evas_gl_common_texture_free
-                         ((Evas_GL_Texture *)gc->shared->tex.atlas[i][j]);
-                       gc->shared->tex.atlas[i][j] = NULL;
-                    }
+                  EINA_LIST_FOREACH(gc->shared->tex.atlas[i][j], l, pt)
+                     evas_gl_texture_pool_empty(pt);
                }
           }
         eina_hash_free(gc->shared->native_hash);
index d10e117..e03b2d9 100644 (file)
@@ -94,7 +94,7 @@ _tex_format_index(GLuint format)
         return 1;
      case GL_ALPHA:
         return 2;
-     case GL_LUMINANCE:
+     case GL_LUMINANCE: // never used in atlas
         return 3;
      default:
         return 0;
@@ -312,10 +312,6 @@ evas_gl_common_texture_new(Evas_GL_Context *gc, RGBA_Image *im)
      }
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x11, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -610,11 +606,10 @@ _pool_tex_dynamic_new(Evas_GL_Context *gc, int w, int h, int intformat, int form
    return pt;
 }
 
-static void
-pt_unref(Evas_GL_Texture_Pool *pt)
+void
+evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt)
 {
-   pt->references--;
-   if (pt->references != 0) return;
+   if (!pt->gc) return;
    
    if (pt->format == alpha_fmt)
       {
@@ -649,14 +644,6 @@ pt_unref(Evas_GL_Texture_Pool *pt)
    
    _print_tex_count();
    
-   if (!((pt->render) || (pt->native)))
-     {
-        if (pt->whole)
-          pt->gc->shared->tex.whole = eina_list_remove(pt->gc->shared->tex.whole, pt);
-        else
-          pt->gc->shared->tex.atlas [pt->slot][pt->fslot] =
-          eina_list_remove(pt->gc->shared->tex.atlas[pt->slot][pt->fslot], pt);
-     }
 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
    if (pt->dyn.img)
      {
@@ -677,11 +664,34 @@ pt_unref(Evas_GL_Texture_Pool *pt)
      {
         glsym_glDeleteFramebuffers(1, &(pt->fb));
         GLERR(__FUNCTION__, __FILE__, __LINE__, "");
+        pt->fb = 0;
+     }
+   while (pt->allocations)
+      pt->allocations = 
+      eina_list_remove_list(pt->allocations, pt->allocations);
+   pt->texture = 0;
+   pt->gc = NULL;
+   pt->w = 0;
+   pt->h = 0;
+}
+
+static void
+pt_unref(Evas_GL_Texture_Pool *pt)
+{
+   if (!pt->gc) return;
+   pt->references--;
+   if (pt->references != 0) return;
+
+   if (!((pt->render) || (pt->native)))
+     {
+        if (pt->whole)
+           pt->gc->shared->tex.whole = 
+           eina_list_remove(pt->gc->shared->tex.whole, pt);
+        else
+           pt->gc->shared->tex.atlas [pt->slot][pt->fslot] =
+           eina_list_remove(pt->gc->shared->tex.atlas[pt->slot][pt->fslot], pt);
      }
-   // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-   // find some mysterious bug i simply have been unable to catch or
-   // reproduce - so leave a trail and see how it goes.
-   memset(pt, 0x22, sizeof(Evas_GL_Texture_Pool));
+   evas_gl_texture_pool_empty(pt);
    free(pt);
 }
 
@@ -712,10 +722,6 @@ evas_gl_common_texture_native_new(Evas_GL_Context *gc, unsigned int w, unsigned
      }
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x33, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -754,10 +760,6 @@ evas_gl_common_texture_render_new(Evas_GL_Context *gc, unsigned int w, unsigned
      }
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x44, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -800,10 +802,6 @@ evas_gl_common_texture_dynamic_new(Evas_GL_Context *gc, Evas_GL_Image *im)
      }
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x55, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -913,10 +911,6 @@ evas_gl_common_texture_free(Evas_GL_Texture *tex)
      }
    if (tex->ptu) pt_unref(tex->ptu);
    if (tex->ptv) pt_unref(tex->ptv);
-   // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-   // find some mysterious bug i simply have been unable to catch or
-   // reproduce - so leave a trail and see how it goes.
-   memset(tex, 0x66, sizeof(Evas_GL_Texture));
    free(tex);
 }
 
@@ -938,10 +932,6 @@ evas_gl_common_texture_alpha_new(Evas_GL_Context *gc, DATA8 *pixels,
                             gc->shared->info.tune.atlas.max_alloc_alpha_size);
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x77, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -985,8 +975,6 @@ Evas_GL_Texture *
 evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h)
 {
    Evas_GL_Texture *tex;
-//   Eina_List *l_after = NULL;
-//   int u = 0, v = 0;
 
    tex = calloc(1, sizeof(Evas_GL_Texture));
    if (!tex) return NULL;
@@ -996,10 +984,6 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, unsigned int w
    tex->pt = _pool_tex_new(gc, w + 1, h  + 1, lum_ifmt, lum_fmt);
    if (!tex->pt)
      {
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x88, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -1010,11 +994,6 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, unsigned int w
    tex->ptu = _pool_tex_new(gc, (w / 2) + 1, (h / 2)  + 1, lum_ifmt, lum_fmt);
    if (!tex->ptu)
      {
-        pt_unref(tex->pt);
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0x99, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }
@@ -1027,10 +1006,6 @@ evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, unsigned int w
      {
         pt_unref(tex->pt);
         pt_unref(tex->ptu);
-        // FIXME: mark as freed for now with 0x66, but this is me TRYING to
-        // find some mysterious bug i simply have been unable to catch or
-        // reproduce - so leave a trail and see how it goes.
-        memset(tex, 0xaa, sizeof(Evas_GL_Texture));
         free(tex);
         return NULL;
      }