Bug 1350924 - [5.0] Only delete textures from a valid context. r=snorp draft
authorEugen Sawin <esawin@mozilla.com>
Wed, 26 Apr 2017 12:24:03 -0500
changeset 568962 c14a224007240c01f9c69eb862c0941cc86602fb
parent 568961 309b8dc72d72cd9bbdc6c7af3657fa827db919c1
child 568963 2741cc1e3187473bbce2c4a52a41882af7b26566
push id56033
push userbmo:snorp@snorp.net
push dateWed, 26 Apr 2017 20:29:44 +0000
reviewerssnorp
bugs1350924
milestone55.0a1
Bug 1350924 - [5.0] Only delete textures from a valid context. r=snorp MozReview-Commit-ID: 4SWJH7CMulH
gfx/layers/opengl/TexturePoolOGL.cpp
--- a/gfx/layers/opengl/TexturePoolOGL.cpp
+++ b/gfx/layers/opengl/TexturePoolOGL.cpp
@@ -74,25 +74,24 @@ GLuint TexturePoolOGL::AcquireTexture()
     NS_ASSERTION(texture, "Failed to retrieve texture from pool");
   }
 
   return texture;
 }
 
 static void Clear()
 {
-  if (!sActiveContext)
-    return;
-
-  sActiveContext->MakeCurrent();
+  const bool isCurrent = sActiveContext && sActiveContext->MakeCurrent();
 
   GLuint* item;
   while (sTextures->GetSize()) {
     item = (GLuint*)sTextures->Pop();
-    sActiveContext->fDeleteTextures(1, item);
+    if (isCurrent) {
+      sActiveContext->fDeleteTextures(1, item);
+    }
     delete item;
   }
 }
 
 void TexturePoolOGL::Fill(GLContext* aContext)
 {
   NS_ASSERTION(aContext, "NULL GLContext");
   NS_ASSERTION(sMonitor, "not initialized");
@@ -102,17 +101,18 @@ void TexturePoolOGL::Fill(GLContext* aCo
   if (sActiveContext != aContext) {
     Clear();
     sActiveContext = aContext;
   }
 
   if (sTextures->GetSize() == TEXTURE_POOL_SIZE)
     return;
 
-  sActiveContext->MakeCurrent();
+  DebugOnly<bool> ok = sActiveContext->MakeCurrent();
+  MOZ_ASSERT(ok);
 
   GLuint* texture = nullptr;
   while (sTextures->GetSize() < TEXTURE_POOL_SIZE) {
     texture = (GLuint*)malloc(sizeof(GLuint));
     sActiveContext->fGenTextures(1, texture);
     sTextures->Push((void*) texture);
   }