From e521638f910314e5a31fe755c38bf7bf07a79980 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 9 Jun 2009 11:13:11 +0100 Subject: [PATCH] [CoglTexture] Initialise tex->first_pixels to NULL in all constructors Otherwise if there is an error before the slices are created it will try to free the first_pixels array and crash. It now also checks whether first_pixels has been created before using it to update the mipmaps. This should only happen for cogl_texture_new_from_foreign and doesn't matter if the FBO extension is available. It would be better in this case to fetch the first pixel using glGetTexImage as Owen mentioned in the last commit. --- gl/cogl-texture.c | 6 +++++- gles/cogl-texture.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index ad25195f9..3af78f9a0 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -1256,6 +1256,7 @@ cogl_texture_new_with_size (guint width, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap.width = width; tex->bitmap.height = height; @@ -1322,6 +1323,7 @@ cogl_texture_new_from_data (guint width, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap.width = width; tex->bitmap.height = height; @@ -1387,6 +1389,7 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap = *bmp; tex->bitmap_owner = FALSE; @@ -1553,6 +1556,7 @@ cogl_texture_new_from_foreign (GLuint gl_handle, tex->is_foreign = TRUE; tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; bpp = _cogl_get_format_bpp (format); tex->bitmap.format = format; @@ -1784,7 +1788,7 @@ _cogl_texture_ensure_mipmaps (CoglHandle handle) /* glGenerateMipmap is defined in the FBO extension */ if (cogl_features_available (COGL_FEATURE_OFFSCREEN)) GE( glGenerateMipmap (tex->gl_target) ); - else + else if (tex->first_pixels) { CoglTexturePixel *pixel = tex->first_pixels + i; /* Temporarily enable automatic mipmap generation and diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index d650b7015..ae3e437b8 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -1331,6 +1331,7 @@ cogl_texture_new_with_size (guint width, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap.width = width; tex->bitmap.height = height; @@ -1397,6 +1398,7 @@ cogl_texture_new_from_data (guint width, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap.width = width; tex->bitmap.height = height; @@ -1460,6 +1462,7 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, tex->is_foreign = FALSE; tex->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; tex->bitmap = *bmp; tex->bitmap_owner = TRUE; @@ -1629,6 +1632,7 @@ cogl_texture_new_from_foreign (GLuint gl_handle, tex->is_foreign = TRUE; tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE; tex->mipmaps_dirty = TRUE; + tex->first_pixels = NULL; bpp = _cogl_get_format_bpp (format); tex->bitmap.format = format; @@ -1860,7 +1864,7 @@ _cogl_texture_ensure_mipmaps (CoglHandle handle) /* glGenerateMipmap is defined in the FBO extension */ if (cogl_features_available (COGL_FEATURE_OFFSCREEN)) GE( cogl_wrap_glGenerateMipmap (tex->gl_target) ); - else + else if (tex->first_pixels) { CoglTexturePixel *pixel = tex->first_pixels + i; /* Temporarily enable automatic mipmap generation and