saveScene doesn't save mesh filename

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

saveScene doesn't save mesh filename

Post by aanderse »

I place some mesh scene nodes on my scene (all .3ds file format)

Code: Select all

scene::IMesh *imesh = scene->getMesh(mesh.c_str());
if(mesh != 0) {
  node = scene->addMeshSceneNode(imesh, 0, NodeMask);
  if(node != 0) {
    node->setMaterialFlag(video::EMF_LIGHTING, false);
    node->setMaterialTexture(0, video->getTexture(texture.c_str()));
  }
}
and it shows up fine, no problem.

But later on I call ISceneManager::saveScene(filename); and it saves the file alright... but the mesh property in xml has no filename. Everything else appears to save fine but not the mesh filename.

EDIT: oops! irrlicht svn revision 1574 is what I tested with
Last edited by aanderse on Sun Sep 21, 2008 5:35 pm, edited 1 time in total.
aanderse
Posts: 155
Joined: Sun Aug 10, 2008 2:02 pm
Location: Canada

update

Post by aanderse »

So I dug around in the sources a little and found the problem. The problem lies in CMeshCache.cpp

Code: Select all

//! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none.
const c8* CMeshCache::getMeshFilename(const IAnimatedMesh* const mesh) const
{
	for (u32 i=0; i<Meshes.size(); ++i)
	{
		if (Meshes[i].Mesh == mesh)
			return Meshes[i].Name.c_str();
	}

	return 0;
}


//! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none.
const c8* CMeshCache::getMeshFilename(const IMesh* const mesh) const
{
	for (u32 i=0; i<Meshes.size(); ++i)
	{
		if (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)
			return Meshes[i].Name.c_str();
	}

	return 0;
}
So in the second function it compares Meshes.Mesh->getMesh(0) to the paramater you pass, mesh. I checked the pointers and Meshes.Mesh is the same value as the parameter mesh which means in my situation the second function should just be comparing Meshes.Mesh and mesh, not Meshes.Mesh->getMesh(0) and mesh (ie. more like the first function).

It could also be that whatever is calling this second function should instead be calling the first function- because if the first function was called it would work fine.
timetokill
Posts: 74
Joined: Tue Jul 22, 2008 4:28 am
Location: Los Angeles

Post by timetokill »

I also am having this issue. It was able to save the path to the .b3d file I'm using, however.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I guess that we need to refactor thw whole MeshCache to IMesh, now that IAnimatedMesh is derived from IMesh. This will also require the ability to check which type of mesh (animated, static, or one of the more specific types) this mesh is, i.e. move getMeshType from IAnimatedMesh to IMesh. Maybe we can also cleanup the mesh types here, because all the minor format types don't help that much, at least if there are no specific properties in a format.
This bug is already tracked, so it won't get lost. However, I'm not sure if it will be resolved until the 1.5 release.
timetokill
Posts: 74
Joined: Tue Jul 22, 2008 4:28 am
Location: Los Angeles

Post by timetokill »

Thanks for keeping track of it, hybrid.

As for now, using the quick fix proposed by kaos (http://irrlicht.sourceforge.net/phpBB2/ ... =savescene) has been sufficient. :)
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

or, we could just paper over it for now by changing the check to:

Code: Select all

//! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none.
const c8* CMeshCache::getMeshFilename(const IMesh* const mesh) const
{
	for (u32 i=0; i<Meshes.size(); ++i)
	{
		// IMesh may actually be an IAnimatedMesh, so do a direct comparison
		// as well as getting an IMesh from our stored IAnimatedMeshes
		if (Meshes[i].Mesh && (Meshes[i].Mesh == mesh || Meshes[i].Mesh->getMesh(0) == mesh))
			return Meshes[i].Name.c_str();
	}

	return 0;
}
We could have that in now, or wait while I investigate the consequences of making IMesh smarterer.

By the way, this is a great bug report, aanderse. I like being pointed at the solution. :)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh yes, the double check looks good for now. This would work for both the basic IMesh structures and those wrapped in an animated mesh. At least as a temporary workaround.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

OK, let's have it in as a stopgap for 1.4.3 / 1.5

Committed in:

Trunk SVN 1674

1.4 branch SVN 1675
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply