[cogl/cogl-1.14] bitmap: don't mark bitmap bound on _gl_bind error



commit b62b9a68bbc3303810576480b39cd2ec20a2ceae
Author: Robert Bragg <robert linux intel com>
Date:   Thu Feb 28 17:48:34 2013 +0000

    bitmap: don't mark bitmap bound on _gl_bind error
    
    This makes some changes to _cogl_bitmap_gl_bind to be more paranoid
    about bad access arguments and make sure we don't mark a bitmap as bound
    if there was an error in _cogl_buffer_gl_bind.
    
    We now validate the access argument upfront to check that one of _READ
    or _WRITE access has been requested. In the case that cogl is built
    without debug support then we will still detect a bad access argument
    later and now explicitly return before marking the bitmap as bound, just
    in case the g_assert_not_reach has been somehow disabled. Finally we
    defer setting bitmap->bound = TRUE until after we have check for any
    error with _cogl_bitmap_gl_bind.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686770
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    
    (cherry picked from commit 1720d5cf32449a189fd9d400cf5e6696cd50a9fa)

 cogl/cogl-bitmap.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c
index 269b5ed..58890fc 100644
--- a/cogl/cogl-bitmap.c
+++ b/cogl/cogl-bitmap.c
@@ -447,6 +447,10 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
   uint8_t *ptr;
   CoglError *internal_error = NULL;
 
+  g_return_val_if_fail (access & (COGL_BUFFER_ACCESS_READ |
+                                  COGL_BUFFER_ACCESS_WRITE),
+                        NULL);
+
   /* Divert to another bitmap if this data is shared */
   if (bitmap->shared_bmp)
     return _cogl_bitmap_gl_bind (bitmap->shared_bmp, access, hints, error);
@@ -463,8 +467,6 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
       return data;
     }
 
-  bitmap->bound = TRUE;
-
   if (access == COGL_BUFFER_ACCESS_READ)
     ptr = _cogl_buffer_gl_bind (bitmap->buffer,
                                 COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
@@ -477,6 +479,7 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
     {
       ptr = NULL;
       g_assert_not_reached ();
+      return NULL;
     }
 
   /* NB: _cogl_buffer_gl_bind() may return NULL in non-error
@@ -488,6 +491,8 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
       return NULL;
     }
 
+  bitmap->bound = TRUE;
+
   /* The data pointer actually stores the offset */
   return ptr + GPOINTER_TO_INT (bitmap->data);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]