Issue with ManualObjects and techniques with vertex shaders

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Issue with ManualObjects and techniques with vertex shaders

Post by peste » Fri Nov 07, 2014 2:01 pm

Hello,

I'm trying to port my application from Ogre 1.8 to 1.9 but I experience a crash when using multi-pass techniques with vertex shaders and meshes converted from manual objects.
The problem arise on Ubuntu 14.04 with NVIDIA drivers.

Here is the stack trace:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00007fffef2c3390 in ?? () from /usr/lib/nvidia-304/libnvidia-glcore.so.304.117
(gdb) bt
#0  0x00007fffef2c3390 in ?? () from /usr/lib/nvidia-304/libnvidia-glcore.so.304.117
#1  0x00007fffef489f30 in ?? () from /usr/lib/nvidia-304/libnvidia-glcore.so.304.117
#2  0x00007fffef48bb5d in ?? () from /usr/lib/nvidia-304/libnvidia-glcore.so.304.117
#3  0x00007fffef0d0924 in ?? () from /usr/lib/nvidia-304/libnvidia-glcore.so.304.117
#4  0x00007fffb674bd97 in Ogre::GLRenderSystem::_render(Ogre::RenderOperation const&) () from lib/RenderSystem_GL.so.1.9.0
#5  0x00007ffff5897994 in Ogre::SceneManager::renderSingleObject(Ogre::Renderable*, Ogre::Pass const*, bool, bool, Ogre::HashedVector<Ogre::Light*> const*) ()
   from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#6  0x00007ffff5895cbb in Ogre::SceneManager::BRAND NAME::visit(Ogre::Renderable*) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#7  0x00007ffff5830b0b in Ogre::QueuedRenderableCollection::acceptVisitorGrouped(Ogre::BRAND NAME*) const () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#8  0x00007ffff5830903 in Ogre::QueuedRenderableCollection::acceptVisitor(Ogre::BRAND NAME*, Ogre::QueuedRenderableCollection::OrganisationMode) const ()
   from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#9  0x00007ffff5896157 in Ogre::SceneManager::renderObjects(Ogre::QueuedRenderableCollection const&, Ogre::QueuedRenderableCollection::OrganisationMode, bool, bool, Ogre::HashedVector<Ogre::Light*> const*) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#10 0x00007ffff5896468 in Ogre::SceneManager::renderBasicQueueGroupObjects(Ogre::RenderQueueGroup*, Ogre::QueuedRenderableCollection::OrganisationMode) ()
   from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#11 0x00007ffff58963d4 in Ogre::SceneManager::_renderQueueGroupObjects(Ogre::RenderQueueGroup*, Ogre::QueuedRenderableCollection::OrganisationMode) ()
   from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#12 0x00007ffff5893a8c in Ogre::SceneManager::renderVisibleObjectsDefaultSequence() () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#13 0x00007ffff58937e8 in Ogre::SceneManager::_renderVisibleObjects() () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#14 0x00007ffff588f2c6 in Ogre::SceneManager::_renderScene(Ogre::Camera*, Ogre::Viewport*, bool) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#15 0x00007ffff5978526 in Ogre::Camera::_renderScene(Ogre::Viewport*, bool) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#16 0x00007ffff5824207 in Ogre::Viewport::update() () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#17 0x00007ffff5720f97 in Ogre::RenderTarget::_updateViewport(Ogre::Viewport*, bool) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#18 0x00007ffff5720eb0 in Ogre::RenderTarget::_updateAutoUpdatedViewports(bool) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#19 0x00007ffff5720de3 in Ogre::RenderTarget::updateImpl() () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
#20 0x00007ffff5722aba in Ogre::RenderTarget::update(bool) () from /home/steficy/develop/webots/lib/libOgreMain_d.so.1.9.0
I tried to simplify my application and this is the scene I create:

Code: Select all

// load default and persistent material from script
Ogre::MaterialManager &mgr = Ogre::MaterialManager::getSingleton();
Ogre::ResourceManager::ResourceCreateOrRetrieveResult result = mgr.createOrRetrieve("RegularDefault", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mDefaultMaterial = static_cast<Ogre::Material *>(result.first.getPointer());

//create camera and viewport
mCamera = mSceneMgr->createCamera("camera");
mViewport = mRenderWindow->addViewport(mCamera);

// create box
double x = 1.0;  double y = 1.0; double z = 1.0;
 
Ogre::ManualObject *o = mSceneMgr->createManualObject("box_mesh_1");
o->estimateVertexCount(24);
o->estimateIndexCount(36);

o->begin("RegularDefault", Ogre::RenderOperation::OT_TRIANGLE_LIST);

// back
o->position(-x,y,-z);  o->textureCoord(1,0);
o->normal(0,0,-1);
o->position(x,y,-z);   o->textureCoord(0,0);
o->position(x,-y,-z);  o->textureCoord(0,1);
o->position(-x,-y,-z); o->textureCoord(1,1);
o->quad(0,1,2,3);

// left
o->position(-x,y,-z);  o->textureCoord(0,0);
o->normal(-1,0,0);
o->position(-x,-y,-z);   o->textureCoord(0,1);
o->position(-x,-y,z);  o->textureCoord(1,1);
o->position(-x,y,z); o->textureCoord(1,0);
o->quad(4,5,6,7);

// bottom
o->position(x,-y,z);  o->textureCoord(1,0);
o->normal(0,-1,0);
o->position(-x,-y,z);   o->textureCoord(0,0);
o->position(-x,-y,-z);  o->textureCoord(0,1);
o->position(x,-y,-z); o->textureCoord(1,1);
o->quad(8,9,10,11);

// front
o->position(x,y,z);  o->textureCoord(1,0);
o->normal(0,0,1);
o->position(-x,y,z);   o->textureCoord(0,0);
o->position(-x,-y,z);  o->textureCoord(0,1);
o->position(x,-y,z); o->textureCoord(1,1);
o->quad(12,13,14,15);

// right
o->position(x,-y,-z);  o->textureCoord(1,1);
o->normal(1,0,0);
o->position(x,y,-z);   o->textureCoord(1,0);
o->position(x,y,z);  o->textureCoord(0,0);
o->position(x,-y,z); o->textureCoord(0,1);
o->quad(16,17,18,19);

// top
o->position(x,y,z);  o->textureCoord(1,1);
o->normal(0,1,0);
o->position(x,y,-z);   o->textureCoord(1,0);
o->position(-x,y,-z);  o->textureCoord(0,0);
o->position(-x,y,z); o->textureCoord(0,1);
o->quad(20,21,22,23);

o->end();
o->convertToMesh("box_mesh_1");
mSceneMgr->destroyManualObject(o);

mGeomEntity = mSceneMgr->createEntity("box_mesh_1", "box_mesh_1");
mGeomEntity->setCastShadows(true);
mGeomNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("box_node");
mGeomNode->attachObject(mGeomEntity);

// create material
Ogre::Material *mat = static_cast<Ogre::Material *>(Ogre::MaterialManager::getSingleton().create("box_1", "General").get());

// remove techniques
Ogre::Material::TechniqueIterator tIt = mat->getTechniqueIterator();
while (tIt.hasMoreElements()) {
  Ogre::Technique *t = tIt.getNext();
  Ogre::Technique::PassIterator pIt = t->getPassIterator();
  while (pIt.hasMoreElements()) {
    Ogre::Pass *p = pIt.getNext();
    p->removeAllTextureUnitStates();
  }
  t->removeAllPasses();
}
mat->removeAllTechniques();
  
Ogre::Technique *t;
Ogre::Pass *p;
t = mat->createTechnique();
t->setName("Approx");
p = t->createPass();
p->setName("Ambient");
p->setLightingEnabled(false);
p = t->createPass();
p->setName("PointLights");
p->setVertexProgram("ApproxPointLightVert");

t = mat->createTechnique();
t->setName("Precise");
p = t->createPass();
p->setName("Ambient");
p->setLightingEnabled(false);
p = t->createPass();
p->setName("PointLights");
p->setVertexProgram("PrecisePointLightVert");

mGeomEntity->setMaterialName("box_1");

// create light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
mLight = mSceneMgr->createLight("pointlight_2");
mLight->setVisible(true);
mLight->setCastShadows(true);
mLight->setType(Ogre::Light::LT_POINT);
mLight->setPosition(2.0f, 5.0f, 8.0f);
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);  
Then I delete the scene and recreate it the same way.
I get the crash during the first rendering after the recreation.

Code: Select all

mRenderWindow->removeViewport(mViewport->getZOrder());
mSceneMgr->destroyCamera(mCamera);

mSceneMgr->destroyLight(mLight);
mLight = NULL;

Ogre::String meshName = mGeomEntity->getMesh()->getName();
mGeomNode->detachObject(mGeomEntity);
mSceneMgr->destroyEntity(mGeomEntity);
mSceneMgr->destroySceneNode(mGeomNode);
Ogre::MeshManager::getSingletonPtr()->remove(meshName);
Ogre::MaterialManager::getSingleton().remove("box_1");
mGeomNode = NULL;
mGeomEntity = NULL;
The problem seems very specific to NVIDIA drivers because running the same application in a virtual machine or on a PC with Intel graphic card works fine.
But it is independent from the code defined in the vertex program and it is working with Ogre 1.8.
I also noticed that if I use a static mesh loaded from file or if I remove the vertex shaders, then the application doesn't crash.

Does anyone have some suggestions about what could be the problem?
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4291
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: Issue with ManualObjects and techniques with vertex shad

Post by spacegaier » Fri Nov 07, 2014 3:02 pm

Where exactly does the scene crash after the recreation?
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Re: Issue with ManualObjects and techniques with vertex shad

Post by peste » Fri Nov 07, 2014 3:19 pm

After recreating the scene I call an update of the render window and it is during this method that crashes:

Code: Select all

mRenderWindow->update(false);
I don't know if there are some methods to see what happens internally in the nvidia driver.
0 x

peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Re: Issue with ManualObjects and techniques with vertex shad

Post by peste » Fri Nov 07, 2014 3:44 pm

It seems to be related to texture mapping as well.
I just noticed that if I remove the definition of texture coordinates from the ManualObject definition, then it works without crashing.

But I'm now testing with simple vertex shaders that don't take care of texture mapping:

Code: Select all

void main()
{
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
0 x

peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Re: Issue with ManualObjects and techniques with vertex shad

Post by peste » Wed Nov 12, 2014 3:56 pm

I'm trying to debug the OgreGLRenderSystem::_render function to check if I can identify the problem, given that the crash arise on the glDrawElements call.
And I found out that GL_TEXTURE_COORD_ARRAY is not always disabled after the draw statement because it doesn't enter the following loop:

Code: Select all

for (unsigned short i = 0; i < std::min((unsigned short)mDisabledTexUnitsFrom, mFixedFunctionTextureUnits); i++)
{
  // No need to disable for texture units that weren't used
  glClientActiveTextureARB(GL_TEXTURE0 + i);
  glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
I'm not sure if this is a problem, but if I call again the statement glDisableClientState( GL_TEXTURE_COORD_ARRAY ) after the loop, then it seems that the crash disappears in case of very simple scenes containing just a point light, a manual object with texture mapping and multiple metrial techniques with vertex shaders.
But I still have the crash for more complex scenes.
0 x

peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Re: Issue with ManualObjects and techniques with vertex shad

Post by peste » Wed Nov 12, 2014 4:47 pm

Disabling also the GL_TEXTURE_COORD_ARRAY for GL_TEXTURE1 and GL_TEXTURE2 too seems to fix the issue in any scene I tested.
I added these line (the first one is already there) just after the loop posted in the previous message.

Code: Select all

glClientActiveTextureARB(GL_TEXTURE0);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glClientActiveTextureARB(GL_TEXTURE1);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glClientActiveTextureARB(GL_TEXTURE2);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
So at this point I'm not sure where are the missing textures coordinate arrays supposed to the disabled and if the problem comes from an error in my code managing my scene or of it is an Ogre 1.9 problem.
0 x

peste
Gnoblar
Posts: 6
Joined: Fri Nov 07, 2014 11:18 am

Re: Issue with ManualObjects and techniques with vertex shad

Post by peste » Wed Nov 12, 2014 5:16 pm

The program doesn't enter the for-loop because mDisabledTexUnitsFrom = 0.
0 x

Post Reply