Bug 1136494 - Validate mActiveProgramLinkInfo in ScopedResolveTexturesForDraw, since it's run first. - r=mtseng draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 14 Jul 2016 10:52:20 -0700
changeset 387740 cfc4efac4a8fab48b6873c4fc490c130a739b9b5
parent 387739 e8d72bb5a06ce79a85b2ac0596da243f7ae0154a
child 387741 5cf41706cdefbd99adfabcd4d16464f59b7bbe12
push id23062
push userbmo:jgilbert@mozilla.com
push dateThu, 14 Jul 2016 19:33:51 +0000
reviewersmtseng
bugs1136494
milestone50.0a1
Bug 1136494 - Validate mActiveProgramLinkInfo in ScopedResolveTexturesForDraw, since it's run first. - r=mtseng MozReview-Commit-ID: Dq8C5OnwjRM
dom/canvas/WebGLContextDraw.cpp
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -89,16 +89,22 @@ WebGLTexture::IsFeedback(WebGLContext* w
 
 ScopedResolveTexturesForDraw::ScopedResolveTexturesForDraw(WebGLContext* webgl,
                                                            const char* funcName,
                                                            bool* const out_error)
     : mWebGL(webgl)
 {
     MOZ_ASSERT(mWebGL->gl->IsCurrent());
 
+    if (!mWebGL->mActiveProgramLinkInfo) {
+        mWebGL->ErrorInvalidOperation("%s: The current program is not linked.", funcName);
+        *out_error = true;
+        return;
+    }
+
     std::vector<const WebGLFBAttachPoint*> fbAttachments;
     if (mWebGL->mBoundDrawFramebuffer) {
         const auto& fb = mWebGL->mBoundDrawFramebuffer;
         fb->GatherAttachments(&fbAttachments);
     }
 
     MOZ_ASSERT(mWebGL->mActiveProgramLinkInfo);
     const auto& uniformSamplers = mWebGL->mActiveProgramLinkInfo->uniformSamplers;
@@ -241,22 +247,16 @@ WebGLContext::DrawArrays_check(GLint fir
         return false;
     }
 
     // If count is 0, there's nothing to do.
     if (count == 0 || primcount == 0) {
         return false;
     }
 
-    // Any checks below this depend on a program being available.
-    if (!mCurrentProgram) {
-        ErrorInvalidOperation("%s: null CURRENT_PROGRAM", info);
-        return false;
-    }
-
     if (!ValidateBufferFetching(info)) {
         return false;
     }
 
     CheckedInt<GLsizei> checked_firstPlusCount = CheckedInt<GLsizei>(first) + count;
 
     if (!checked_firstPlusCount.isValid()) {
         ErrorInvalidOperation("%s: overflow in first+count", info);
@@ -406,24 +406,16 @@ WebGLContext::DrawElements_check(GLsizei
     const GLsizei first = byteOffset / bytesPerElem;
     const CheckedUint32 checked_byteCount = bytesPerElem * CheckedUint32(count);
 
     if (!checked_byteCount.isValid()) {
         ErrorInvalidValue("%s: overflow in byteCount", info);
         return false;
     }
 
-    // Any checks below this depend on mActiveProgramLinkInfo being available.
-    if (!mActiveProgramLinkInfo) {
-        // Technically, this will only be null iff CURRENT_PROGRAM is null.
-        // But it's better to branch on what we actually care about.
-        ErrorInvalidOperation("%s: null CURRENT_PROGRAM", info);
-        return false;
-    }
-
     if (!mBoundVertexArray->mElementArrayBuffer) {
         ErrorInvalidOperation("%s: must have element array buffer binding", info);
         return false;
     }
 
     WebGLBuffer& elemArrayBuffer = *mBoundVertexArray->mElementArrayBuffer;
 
     if (!elemArrayBuffer.ByteLength()) {