Bug 1394265 - LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS returns negative value, causing OOM crash. draft
authorChung-Sheng Fu <cfu@mozilla.com>
Thu, 31 Aug 2017 15:56:43 +0800
changeset 656434 4c180a2f2e91be54e929a53055c7984e2dd4442f
parent 656346 04b6be50a2526c7a26a63715f441c47e1aa1f9be
child 729155 842158c8fa262b0b72ffca5f3ead8ebe2cbe3ad1
push id77229
push userbmo:cfu@mozilla.com
push dateThu, 31 Aug 2017 07:58:21 +0000
bugs1394265
milestone57.0a1
Bug 1394265 - LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS returns negative value, causing OOM crash. MozReview-Commit-ID: E3nzmXZtTqK
dom/canvas/WebGLContextValidate.cpp
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -505,29 +505,36 @@ WebGLContext::InitAndValidateGL(FailureR
 
     if (mGLMaxVertexAttribs < 8) {
         const nsPrintfCString reason("GL_MAX_VERTEX_ATTRIBS: %d is < 8!",
                                      mGLMaxVertexAttribs);
         *out_failReason = { "FEATURE_FAILURE_WEBGL_V_ATRB", reason };
         return false;
     }
 
+    // Bug 1394265, somehow LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
+    // sometimes returns negative value, the unsigned mGLMaxTextureUnits
+    // is not able to tell the failure.
+    GLint maxTextureUnits = 0;
+
     // Note: GL_MAX_TEXTURE_UNITS is fixed at 4 for most desktop hardware,
     // even though the hardware supports much more.  The
     // GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value is the accurate value.
-    gl->GetUIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGLMaxTextureUnits);
-    mGLMaxCombinedTextureImageUnits = mGLMaxTextureUnits;
+    gl->fGetIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
 
-    if (mGLMaxTextureUnits < 8) {
-        const nsPrintfCString reason("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %u is < 8!",
-                                     mGLMaxTextureUnits);
+    if (maxTextureUnits < 8) {
+        const nsPrintfCString reason("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!",
+                                     maxTextureUnits);
         *out_failReason = { "FEATURE_FAILURE_WEBGL_T_UNIT", reason };
         return false;
     }
 
+    mGLMaxTextureUnits = maxTextureUnits;
+    mGLMaxCombinedTextureImageUnits = maxTextureUnits;
+
     mBound2DTextures.SetLength(mGLMaxTextureUnits);
     mBoundCubeMapTextures.SetLength(mGLMaxTextureUnits);
     mBound3DTextures.SetLength(mGLMaxTextureUnits);
     mBound2DArrayTextures.SetLength(mGLMaxTextureUnits);
     mBoundSamplers.SetLength(mGLMaxTextureUnits);
 
     gl->fGetIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, (GLint*)mGLMaxViewportDims);