saveScene vs loadScene Inconsistency

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
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

saveScene vs loadScene Inconsistency

Post by clarks »

Read the code below very carefully, you will notice that serializeAttributes actually uses the options but deserializeAttributes does not. This is a bug. By default the scene manager passes the option to use relative file names, which the user seem to have
no control over. I am not sure if there is a way to control the options flag, but if a scene is saved using relative filename, then
it should be loaded the same way. One does have the option of using the ISceneUserDataSerializer but it does not solve this problem. There needs to be a thorough review of how irrlicht saves and loads scenes.

Code: Select all

 
//! Writes attributes of the scene node.
void CMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
    IMeshSceneNode::serializeAttributes(out, options);
 
    if (options && (options->Flags&io::EARWF_USE_RELATIVE_PATHS) && options->Filename)
    {
        const io::path path = SceneManager->getFileSystem()->getRelativeFilename(
                SceneManager->getFileSystem()->getAbsolutePath(SceneManager->getMeshCache()->getMeshName(Mesh).getPath()),
                options->Filename);
        out->addString("Mesh", path.c_str());
    }
    else
        out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getPath().c_str());
    out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
}
 
 
//! Reads attributes of the scene node.
void CMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
    io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh);
    io::path newMeshStr = in->getAttributeAsString("Mesh");
    ReadOnlyMaterials = in->getAttributeAsBool("ReadOnlyMaterials");
 
    if (newMeshStr != "" && oldMeshStr != newMeshStr)
    {
        IMesh* newMesh = 0;
        IAnimatedMesh* newAnimatedMesh = SceneManager->getMesh(newMeshStr.c_str());
 
        if (newAnimatedMesh)
            newMesh = newAnimatedMesh->getMesh(0);
 
        if (newMesh)
            setMesh(newMesh);
    }
 
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: saveScene vs loadScene Inconsistency

Post by hybrid »

Not sure if this is really required. After all, this will only affect the internal name after deserialization. There's actually no difference, as another serialization with the proper options will result in the same file again. At least for the mesh. Textures a re a different thing and IIRC are not yet properly handled in this place. But that's known and will eventually be fixed.
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: saveScene vs loadScene Inconsistency

Post by clarks »

IIRC are not yet properly handled
what is IIRC?
as another serialization with the proper options will result in the same file again
Do you mine elaborating on this?

I ran a test and found out that if you save a scene using irrlicht, the relative paths are messed up if the file being saved is not in the save directory as the binary.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: saveScene vs loadScene Inconsistency

Post by hybrid »

IIRC means 'if I recall correctly'
My assumption on the behavior would be that you can load and save a scene multiple times, and the results of the saved versions would be always exactly the same - depending on the options used. That would be the correct case at least. For meshes, this worked in the past, but the test is currently disabled as textures do not work properly. If you also find problems with mesh names, please present some test files.
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: saveScene vs loadScene Inconsistency

Post by clarks »

one test case coming up
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: saveScene vs loadScene Inconsistency

Post by hybrid »

Ok, at least a little problem with texture deserialization is solved. Right now I cannot see a relation to the saveScene, because the scene won't load either before or after the saveScene. Seems like the load commands in deserialization have problems when finding certain assets. Not sure why, yet.
clarks
Posts: 35
Joined: Sat Jul 28, 2012 5:23 am

Re: saveScene vs loadScene Inconsistency

Post by clarks »

Seems like the load commands in deserialization have problems when finding certain assets. Not sure why, yet
If you load a scene from a file, and all resources are local to the parent directory of the file, then you have set that directory as the working directory before you load the resources. The problem is that irrlicht does not do that because it assumes that all resources are relative to the dll or the working directory currently set. You have to set the working directory of the scene being loaded in order to properly find of all the resources.
Post Reply