I request a mini fool-proof feature that Ogre should crash when it detects non-unique name when call :-
Code: Select all
Ogre::MeshManager::getSingleton().createManual("must...be...a...unique..name..for..each..meshV2")
Situation that can cause issue
Assume that I have a blender model with embedded invalid material - named material.001.
I loaded it and converted it to V2 two times (to meshPtr & meshPtr2), using exactly same name - "AAA".
Then I reassign meshPtr2 to use another material - named DebugCube as followed:-
Code: Select all
//this is pseudo code
meshV1 = ....
meshPtr = Ogre::MeshManager::getSingleton().createManual("AAA"); meshPtr ->importV1(meshV1);
meshPtr2 = Ogre::MeshManager::getSingleton().createManual("AAA"); meshPtr2 ->importV1(meshV1);
meshPtr2->getSubMesh(0)->setMaterialName("DebugCube");
//^^^ Let's assume that DebugCube is valid && meshPtr2 has only 1 subMesh
Ogre::Item* entity2 = this->mSceneMgr()->createItem(meshPtr2);
Here is the stack when the warning "Can't assign material" occurs:
Code: Select all
OgreMain_d.dll!Ogre::Renderable::setMaterialName Line 156
OgreMain_d.dll!Ogre::Renderable::setDatablockOrMaterialName Line 83
OgreMain_d.dll!Ogre::Item::buildSubItems Line 277
OgreMain_d.dll!Ogre::Item::_initialise Line 112
OgreMain_d.dll!Ogre::Item::Item Line 71
OgreMain_d.dll!Ogre::ItemFactory::createInstanceImpl Line 401
OgreMain_d.dll!Ogre::MovableObjectFactory::createInstance Line 874
OgreMain_d.dll!Ogre::SceneManager::createMovableObject Line 4871
OgreMain_d.dll!Ogre::SceneManager::createItem Line 417
OgreMain_d.dll!Ogre::SceneManager::createItem Line 424
myCode.exe!Graphic_Factory::newBlenderGraphic Line 76
Code: Select all
void Renderable::setMaterialName( const String& name, const String& groupName ) //<-- name = "Material.001" wrong!
{
MaterialPtr material = MaterialManager::getSingleton().getByName( name, groupName );
//^^^^^^^^^^ material = {pRep=0x00000000 <NULL> pInfo=0x00000000 <NULL> }
if( material.isNull() )
{
//It output "Can't assign material " .........
Inside Ogre, OgreSceneManager.cpp shows that Ogre pass string-name of MeshPtr as parameter
(instead of passing mesh's pointer) :-
Code: Select all
Item* SceneManager::createItem( const MeshPtr& pMesh, SceneMemoryMgrTypes sceneType )
{
return createItem(pMesh->getName(), pMesh->getGroup(), sceneType); //<--- passing by string name
}
In other words, there are 2 meshPtr with the same string-name, it pick-up a wrong one in this case.
This can cause minor hard-to-track bug for user code.