Edit

kc3-lang/angle/src/libGLESv2/Fence.cpp

Branch :

  • Show log

    Commit

  • Author : apatrick@chromium.org
    Date : 2012-03-23 21:18:42
    Hash : 563c0a53
    Message : Fence has pointer to the associated egl::Display. I think the assumption that getDisplay() returns a valid display in the Fence destructor is wrong. I'm trying to fix a crash in the field that looks like this: Thread 0 *CRASHED* ( EXCEPTION_ACCESS_VIOLATION_READ @ 0x00000000 ) 0x69582e38 [libglesv2.dll - fence.cpp:27 gl::Fence::~Fence() 0x69582f29 [libglesv2.dll + 0x00022f29] gl::Fence::`scalar deleting destructor'(unsigned int) 0x6958077d [libglesv2.dll - context.cpp:1020 gl::Context::deleteFence(unsigned int) 0x69582b9b [libglesv2.dll - context.cpp:195 gl::Context::~Context() 0x69582dcb [libglesv2.dll + 0x00022dcb] gl::Context::`scalar deleting destructor'(unsigned int) 0x69582df2 [libglesv2.dll - context.cpp:4259 glDestroyContext 0x73166ab8 [libegl.dll - display.cpp:768 egl::Display::destroyContext(gl::Context *) 0x73168393 [libegl.dll - libegl.cpp:861 eglDestroyContext 0x6e18f1db [chrome.dll - gl_context_egl.cc:76 gfx::GLContextEGL::Destroy() 0x6e18f40d [chrome.dll - gl_context_egl.cc:43 gfx::GLContextEGL::~GLContextEGL() Here's the disassembly: 69582E21 push esi 69582E22 mov esi,ecx 69582E24 cmp dword ptr [esi+4],0 69582E28 mov dword ptr [esi],695CBBE0h 69582E2E je 69582E3F 69582E30 call 695743F5 // this is getDisplay() 69582E35 push dword ptr [esi+4] 69582E38 mov edx,dword ptr [eax] // crashes here because EAX is zero 69582E3A mov ecx,eax 69582E3C call dword ptr [edx+24h] // this is freeEventQuery() 69582E3F pop esi 69582E40 ret It looks like getDisplay() returns null. http://code.google.com/p/chromium/issues/detail?id=117817 Review URL: https://codereview.appspot.com/5875044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1008 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/libGLESv2/Fence.cpp
  • //
    // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // Fence.cpp: Implements the gl::Fence class, which supports the GL_NV_fence extension.
    
    #include "libGLESv2/Fence.h"
    
    #include "libGLESv2/main.h"
    
    namespace gl
    {
    
    Fence::Fence(egl::Display* display)
    {
        mDisplay = display;
        mQuery = NULL;
        mCondition = GL_NONE;
        mStatus = GL_FALSE;
    }
    
    Fence::~Fence()
    {
        if (mQuery != NULL)
        {
            mDisplay->freeEventQuery(mQuery);
        }
    }
    
    GLboolean Fence::isFence()
    {
        // GL_NV_fence spec:
        // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.
        return mQuery != NULL;
    }
    
    void Fence::setFence(GLenum condition)
    {
        if (!mQuery)
        {
            mQuery = mDisplay->allocateEventQuery();
            if (!mQuery)
            {
                return error(GL_OUT_OF_MEMORY);
            }
        }
    
        HRESULT result = mQuery->Issue(D3DISSUE_END);
        ASSERT(SUCCEEDED(result));
    
        mCondition = condition;
        mStatus = GL_FALSE;
    }
    
    GLboolean Fence::testFence()
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION, GL_TRUE);
        }
    
        HRESULT result = mQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
    
        if (checkDeviceLost(result))
        {
           return error(GL_OUT_OF_MEMORY, GL_TRUE);
        }
    
        ASSERT(result == S_OK || result == S_FALSE);
        mStatus = result == S_OK;
        return mStatus;
    }
    
    void Fence::finishFence()
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION);
        }
    
        while (!testFence())
        {
            Sleep(0);
        }
    }
    
    void Fence::getFenceiv(GLenum pname, GLint *params)
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION);
        }
    
        switch (pname)
        {
            case GL_FENCE_STATUS_NV:
            {
                // GL_NV_fence spec:
                // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
                // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
                if (mStatus)
                {
                    params[0] = GL_TRUE;
                    return;
                }
                
                HRESULT result = mQuery->GetData(NULL, 0, 0);
                
                if (checkDeviceLost(result))
                {
                    params[0] = GL_TRUE;
                    return error(GL_OUT_OF_MEMORY);
                }
    
                ASSERT(result == S_OK || result == S_FALSE);
                mStatus = result == S_OK;
                params[0] = mStatus;
                
                break;
            }
            case GL_FENCE_CONDITION_NV:
                params[0] = mCondition;
                break;
            default:
                return error(GL_INVALID_ENUM);
                break;
        }
    }
    
    }