Fix null context GenBuffers
authorcdalton <cdalton@nvidia.com>
Wed, 6 Apr 2016 20:36:38 +0000 (13:36 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 6 Apr 2016 20:36:38 +0000 (13:36 -0700)
Fixes the null context to not return 0 for GenBuffers.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1863923003

Review URL: https://codereview.chromium.org/1863923003

src/gpu/gl/GrGLCreateNullInterface.cpp

index b9a29fb7421d3a117f3768d0a84b6ea613ae454a..80a7cfbd2cdba26465042be242be89925edf01e0 100644 (file)
@@ -47,7 +47,9 @@ private:
 // This class maintains a sparsely populated array of buffer pointers.
 class BufferManager {
 public:
-    BufferManager() : fFreeListHead(kFreeListEnd) {}
+    BufferManager() : fFreeListHead(kFreeListEnd) {
+        *fBuffers.append() = nullptr; // 0 is not a valid GL buffer id.
+    }
 
     ~BufferManager() {
         // nullptr out the entries that are really free list links rather than ptrs before deleting.
@@ -89,6 +91,7 @@ public:
     }
 
     void free(BufferObj* buffer) {
+        SkASSERT(buffer);
         SkASSERT(fBuffers.count() > 0);
 
         GrGLuint id = buffer->id();
@@ -201,8 +204,10 @@ public:
                 fCurrPixelUnpackBuffer = 0;
             }
 
-            BufferObj* buffer = fBufferManager.lookUp(ids[i]);
-            fBufferManager.free(buffer);
+            if (ids[i] > 0) {
+                BufferObj* buffer = fBufferManager.lookUp(ids[i]);
+                fBufferManager.free(buffer);
+            }
         }
     }