Crash when updating RTT

Problems building or running the engine, queries about how to use features etc.
Post Reply
FloydPepper
Gnoblar
Posts: 9
Joined: Tue May 22, 2018 1:58 pm
Location: France
x 1

Crash when updating RTT

Post by FloydPepper »

Ogre Version: 1.10.11
Operating System: Windows 10 x64
Render System: OpenGL for the first problem, D3D 9 for the second

Hi,

I have a depth map that I need to update. With OpenGL, I have a crash when updating my render texture by calling this:

Code: Select all

pDepthMapRT->update();
This crash appears only after many calls to the update function (around 40 calls).
The exact place where it crash is in bindGpuProgramParameters() method:

Code: Select all

//---------------------------------------------------------------------
    void GLRenderSystem::bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask)
    {
        if (mask & (uint16)GPV_GLOBAL)
        {
            // We could maybe use GL_EXT_bindable_uniform here to produce Dx10-style
            // shared constant buffers, but GPU support seems fairly weak?
            // for now, just copy
            params->_copySharedParams();
        }

        switch (gptype)
        {
        case GPT_VERTEX_PROGRAM:
            mActiveVertexGpuProgramParameters = params;
            mCurrentVertexProgram->bindProgramParameters(params, mask); <-------- It crashes here
            break;
        case GPT_GEOMETRY_PROGRAM:
            mActiveGeometryGpuProgramParameters = params;
            mCurrentGeometryProgram->bindProgramParameters(params, mask);
            break;
        case GPT_FRAGMENT_PROGRAM:
            mActiveFragmentGpuProgramParameters = params;
            mCurrentFragmentProgram->bindProgramParameters(params, mask);
            break;
        case GPT_COMPUTE_PROGRAM:
        case GPT_DOMAIN_PROGRAM:
        case GPT_HULL_PROGRAM:
            break;
        }
    }

With D3D, the crash occurs when trying to copy the pixel buffer contents to a pixel box using the blitToMemoryMethod:

Code: Select all

Ogre::Box extents(0, 0, nXSize, nYSize);
Ogre::PixelBox pb(extents, format, data);
pPixelBuffer->blitToMemory(pb);
This one occurs always at the 16th call.
The exact place where it crash is:

Code: Select all

// Lock temp surface and copy it to memory
        D3DLOCKED_RECT lrect; // Filled in by D3D
        if(surface->LockRect(&lrect, NULL,  D3DLOCK_READONLY) != D3D_OK) <------- It crashes here
        {
            surface->Release();
            tmp->Release();
            OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "surface->LockRect",
                "D3D9HardwarePixelBuffer::blitToMemory");
        }
        // Copy it
        PixelBox locked(dst.getWidth(), dst.getHeight(), dst.getDepth(), tmpFormat);
        fromD3DLock(locked, lrect);
        PixelUtil::bulkPixelConversion(locked, dst);
        surface->UnlockRect();
        // Release temporary surface and texture
        surface->Release();
        tmp->Release();
Here is my complete code:

Code: Select all

    // Create the texture
    Ogre::TexturePtr texPtr = Ogre::TextureManager::getSingleton().getByName("DepthMap");
    if (!texPtr)
    {
      texPtr = Ogre::TextureManager::getSingleton().createManual("DepthMap", kDefaultRessourceGroupName, Ogre::TEX_TYPE_2D, nXSize, nYSize, 0, Ogre::PF_FLOAT32_R, Ogre::TU_RENDERTARGET);
      if (!texPtr)
      {
        ASSERT(FALSE);
        return FALSE;
      }
    }
    else
    {
      texPtr->setWidth(nXSize);
      texPtr->setHeight(nYSize);
    }
    
    // create the render texture
    Ogre::RenderTexture *pDepthMapRT = texPtr->getBuffer()->getRenderTarget();
    
    pDepthMapRT->setAutoUpdated(false);
    pDepthMapRT->setPriority(0);
    
    if (pDepthMapRT->getNumViewports() == 0)
    {
      Ogre::Viewport* pViewport = pDepthMapRT->addViewport(pCamera);
      if (pViewport != nullptr)
      {
        pViewport->setClearEveryFrame(true);
      }
    }
    
    // Create the material
    Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("DepthMap", kMountainsDefaultRessourceGroupName);
    if (!matPtr)
    {
      ASSERT(FALSE);
      return FALSE;
    }
    
    Ogre::TextureUnitState* pTextUnitState = matPtr->getTechnique(0)->getPass(0)->getTextureUnitState("DepthMap");
    if (pTextUnitState == nullptr)
    {
      matPtr->getTechnique(0)->getPass(0)->createTextureUnitState("DepthMap");
    }
    matPtr->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);
    matPtr->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
    matPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    
    // This is the problematic line (with OpenGL)
    pDepthMapRT->update();
        
    // Create a buffer to recieve the content of the texture
    unsigned char *data = new unsigned char[nXSize * nYSize * outBytesPerPixel];   
        
    Ogre::HardwarePixelBufferSharedPtr pPixelBuffer = texPtr->getBuffer();
    if (!pPixelBuffer)
    {
      ASSERT(FALSE);
      return FALSE;
    }

    Ogre::Box extents(0, 0, nXSize, nYSize);
    Ogre::PixelBox pb(extents, format, data);
    
    // Copy the pixel buffer contents to the pixel box
    // This is the line which leads to a crash with D3D
    pPixelBuffer->blitToMemory(pb);    
    
    // Get the datas as floats
    float* pValues = (float*)pb.data;
Does anyone has an idea of the problem ?

Thanks ! :)
Last edited by FloydPepper on Thu Aug 23, 2018 10:08 am, edited 1 time in total.
FloydPepper
Gnoblar
Posts: 9
Joined: Tue May 22, 2018 1:58 pm
Location: France
x 1

Re: Crash when updating RTT

Post by FloydPepper »

This is my log (just before the crash with D3D):

Code: Select all

10:26:23: Note: Texture instance 'DepthMap' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
10:26:23: D3D9 device: 0x[00000000085D9760] lost. Releasing D3D9 texture: DepthMap
10:26:23: Released D3D9 texture: DepthMap
10:26:23: D3D9 Device 0x[00000000085D9760] entered lost state
10:26:23: HardwareBufferManager: No unused temporary vertex buffers found.
10:26:23: !!! Direct3D Device successfully restored.
10:26:23: D3D9 device: 0x[00000000085D9760] was reset
FloydPepper
Gnoblar
Posts: 9
Joined: Tue May 22, 2018 1:58 pm
Location: France
x 1

Re: Crash when updating RTT

Post by FloydPepper »

Nobody ?

If you need more details, I can provide them.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Crash when updating RTT

Post by paroj »

please update to 1.10.12, where this bug was possibly fixed:
https://github.com/OGRECave/ogre/releases/tag/v1.10.12
FloydPepper
Gnoblar
Posts: 9
Joined: Tue May 22, 2018 1:58 pm
Location: France
x 1

Re: Crash when updating RTT

Post by FloydPepper »

I have done the update to 1.10.12, I still have the crashes.
Post Reply