GPU side memory leak?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
wolfgang
Posts: 9
Joined: Mon Jul 01, 2019 8:14 am

GPU side memory leak?

Post by wolfgang »

Hi,

I'm wondering if the following steps would create a memory leak on GPU side:

1. Create an SMeshBuffer with some content
2. Use setHardwareMappingHint(EHM_STATIC)
3. Render it many times via IVideoDriver::drawMeshBuffer
4. Delete the SMeshBuffer

I believe the Vertex Buffer Objects still persist although they are never used again and therefore are a memory leak on GPU side.
Is this correct? If yes: How do I properly handle this situation?
wolfgang
Posts: 9
Joined: Mon Jul 01, 2019 8:14 am

Re: GPU side memory leak?

Post by wolfgang »

I believe I found the solution: IVideoDriver::removeHardwareBuffer must be called to avoid the memory leak when deleting the meshbuffer.

Btw: After looking at the code of CMeshCache::removeMesh I believe I found a bug. This function does not remove the hardware buffers when deleting a mesh:

Code: Select all

void CMeshCache::removeMesh(const IMesh* const mesh)
{
    if ( !mesh )
        return;
    for (u32 i=0; i<Meshes.size(); ++i)
    {
        if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh))
        {
            Meshes[i].Mesh->drop();
            Meshes.erase(i);
            return;
        }
    }
}
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GPU side memory leak?

Post by CuteAlien »

deleteHardwareBuffer is used. Check CNullDriver::updateAllHardwareBuffers() - it has some timeout. Don't know details or reason right now, but basically it's released after 20 seconds.

edit: I suspect there is no reason that it's not release immediately (didn't debug right now - maybe it even is?). The 20 seconds seems to be for another reason. Basically hardwarebuffers are only kept when they are regularly used. So when it's 20 seconds not used it gets kicked and re-created next it _is_ used.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply