Memory corruption using OpenGL ES 2

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Memory corruption using OpenGL ES 2

Post by lscandolo » Tue Aug 27, 2013 7:30 pm

Hi all,

I'm developing an application using OGRE 1.9 on an ARM MALI400, which uses opengles 2. I need to have a constantly updating mesh (vertex and index modification/addition). I use gamekit on top of OGRE, and reload the gamekit mesh each frame. The gamekit mesh is just a thin wrapper around an OGRE mesh, so the reload basically does a basic OGRE unload of the ogre mesh object, and then loads the mesh again using gamekit code, which creates the necessary OGRE hardware buffers and vertex bindings.

Everything runs fine (I see the mesh update in real time), but after some time, I run out of video memory. Nothing else is changing in the scene. If the mesh grows to lets say 1000 vertices, and I don't add any more, but I reload the mesh each frame, it still eventually crashes, if the mesh is smaller, it takes a longer time but it still crashes, which leads me to believe that the hardware buffers are not being freed correctly (and thus accumulate and eventually fill up my video memory). The video memory is not shared with the CPU, so this is extrictly a gpu problem.

The code is part of a bigger project, so right now I'm working on creating a small snippet that reproduces the error, and will post it as soon as I have it, but in the meantime, has anyone run into this sort of problem before, or can point to anything I can verify? The OGRE mesh manager reports the correct ammount of meshes, and they have the amount of vertices/indices I would expect. I'm also calling on the HardwareBufferManager::_releaseBufferCopies and ::_freeUnusedBufferCopies regularly. The code runs fine on PC with OpenGL, it only runs out of memory (even when managing only a mesh with 5000 vertices) only when using the MALi device, which uses OpenGL ES 2.

This is a part of the gamekit code that creates the ogre mesh:

Code: Select all

        Ogre::SubMesh* submesh;
	submesh->vertexData = new Ogre::VertexData();
	submesh->vertexData->vertexCount = vBufSize;

	// disable sharing
	submesh->useSharedVertices = false;

	// converting to tri list
	submesh->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;

	UTsize offs = 0;

	// fill in the declaration
	Ogre::VertexDeclaration* decl = submesh->vertexData->vertexDeclaration;


	// position
	decl->addElement(0, offs, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
	offs += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);

	// no, blending weights

	// normals
	decl->addElement(0, offs, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
	offs += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);

	// texture coordinates
	int maxTco = gks->getUvLayerCount();
	for (int lay = 0; lay < maxTco; ++lay)
	{
		decl->addElement(0, offs, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, lay);
		offs += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
	}

	bool diffuseVert = gks->hasVertexColors();
	if (diffuseVert)
	{
		// diffuse colours
		decl->addElement(0, offs, Ogre::VET_COLOUR_ABGR, Ogre::VES_DIFFUSE);
		offs += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR_ABGR);
	}

	// no, specular colours
	Ogre::HardwareVertexBufferSharedPtr vertBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offs,
	        submesh->vertexData->vertexCount,
	        Ogre::HardwareBuffer::HBU_DYNAMIC);


	// bind the source
	Ogre::VertexBufferBinding* bind = submesh->vertexData->vertexBufferBinding;
	bind->setBinding(0, vertBuf);

	// index buffer
	Ogre::HardwareIndexBuffer::IndexType buff_type = (iBufSize > gk16BitClamp) ?
	        Ogre::HardwareIndexBuffer::IT_32BIT : Ogre::HardwareIndexBuffer::IT_16BIT;

	Ogre::HardwareIndexBufferSharedPtr indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(buff_type,
	        iBufSize,
	        Ogre::HardwareBuffer::HBU_DYNAMIC);


	submesh->indexData->indexCount = iBufSize;
	submesh->indexData->indexBuffer = indexBuffer;
Any ideas are welcome!
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Memory corruption using OpenGL ES 2

Post by masterfalcon » Wed Aug 28, 2013 12:45 am

Is this the code that's needed to reproduce the issue?

Have you checked that VRAM usage isn't also increasing on desktops? It may just run out faster on mobile.
0 x

lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Re: Memory corruption using OpenGL ES 2

Post by lscandolo » Wed Aug 28, 2013 10:33 pm

I'm pretty sure the same behavior is not present when I use OpenGL, I left it with a small test program reloading meshes with 50000 vertices for hours, and it will not crash, whereas the same thing will leave me out of memory in seconds using OpenGL ES 2 (I know that is not a very scientific way, but I haven't found a good vram profiler for the crappy intel card I have on my pc :D ). I'm using the RC1, so I'll try updating to the latest release, and I'll also try just creating a big mesh and modifying it (not throwing away any buffers), and see what happens. Will let you know when I have more info :o
0 x

lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Re: Memory corruption using OpenGL ES 2

Post by lscandolo » Thu Aug 29, 2013 4:26 pm

Just a little update, if I just create a mesh and update it instead of reloading it (just normal hardwarebuffer lock/unlock), the problem goes away, so the reloading code (either my/gamekit's or Ogre's rendersystem) is definitely the culprit here. I had already checked that VRAM doesnt fill up with the GL rendersytem, still, I'll keep digging since this solution is suboptimal for me, at least since updating the vertex buffer is fast, but updating the index buffer is slower (maybe someone can point as to why this could be?)
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Memory corruption using OpenGL ES 2

Post by masterfalcon » Fri Aug 30, 2013 8:11 am

That's interesting. What platform is this on? And were you able to create a code sample for testing?
0 x

lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Re: Memory corruption using OpenGL ES 2

Post by lscandolo » Mon Sep 02, 2013 1:43 pm

Sorry it took some time to reply, had some travelling to do :) As for the test program, I tried it with the Tutorial Framework application from the wiki tutorials, by just setting up the scene with a simple

Code: Select all

 // Set the scene's ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
 
    // Create an Entity
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    // Create a SceneNode and attach the Entity to it
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode");
    headNode->attachObject(ogreHead);
 
    // Create a Light and set its position
    Ogre::Light* light = mSceneMgr->createLight("MainLight");
    light->setPosition(20.0f, 80.0f, 50.0f);    
and then doing

Code: Select all

    Ogre::Entity* head = mSceneMgr->getEntity("Head");
    head->getMesh()->reload();
inside the frameRenderingQueued function, so that it gets called every frame. This leaves me out of memory in about a minute or so.

*Edit: The platform is a tablet with an A13 processor and a Mali400 gpu.
0 x

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Memory corruption using OpenGL ES 2

Post by masterfalcon » Mon Sep 02, 2013 7:26 pm

Nexus 7 or similar? Is it android? If so, what version?
0 x

lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Re: Memory corruption using OpenGL ES 2

Post by lscandolo » Mon Sep 02, 2013 9:25 pm

The tablet is a chinese tablet (momo), running linaro-quantal linux.

/proc/cpuinfo says

Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 1006.38
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x3
CPU part : 0xc08
CPU revision : 2
Hardware : sun5i
0 x

lscandolo
Gnoblar
Posts: 17
Joined: Tue Apr 30, 2013 5:17 pm

Re: Memory corruption using OpenGL ES 2

Post by lscandolo » Thu Sep 05, 2013 8:33 pm

Ok, I was finally able to test the problem with the newest version of the trunk (1.9 branch), and it works fine now (was testing with the RC). It took me a while to get it to work because of this bug.
0 x

Post Reply