[fixed]fs::removeFileArchive fails

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
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

[fixed]fs::removeFileArchive fails

Post by stefbuet »

I can't remove loaded archives from filesystem with IFileSystem::removeFileArchive method.

Code to reproduce problem:

Code: Select all

#include <cstdlib>
#include <iostream>
#include <IRR/irrlicht.h>
 
 
using namespace irr;
using namespace io;
 
 
int main() {
 
    IrrlichtDevice *device=createDevice(video::EDT_OPENGL, core::dimension2d<u32>(512,512),16,false, false, false);
   
    IFileSystem *fs=device->getFileSystem();
         
    std::cout<<"archives : "<<fs->getFileArchiveCount()<<std::endl;
   
    std::cout<<"Adding an archive : "<<fs->addFileArchive("test.zip")<<std::endl;
   
  
    std::cout<<"archives : "<<fs->getFileArchiveCount()<<std::endl;
   
    std::cout<<"Removing an archive : "<<fs->removeFileArchive("test.zip")<<std::endl;
   
    std::cout<<"archives : "<<fs->getFileArchiveCount()<<std::endl;
 
 
   device->drop();
   
   system("PAUSE");
   
   return(0);
 
}
 
Output:

Code: Select all

archives : 0
Adding an archive : 1
archives : 1
Removing an archive : 0
archives : 1
This is because removeFileArchive is checking a relative path against an absolute one.

To remove this problem just change the following :

in CFileSystem.cpp, line 842:

from:

Code: Select all

 
if (filename == FileArchives[i]->getFileList()->getPath())
 
to :

Code: Select all

 
if (getAbsolutePath(filename) == FileArchives[i]->getFileList()->getPath())
 
full function:

Code: Select all

 
//! removes an archive from the file system.
bool CFileSystem::removeFileArchive(const io::path& filename)
{
        for (u32 i=0; i < FileArchives.size(); ++i)
        {
                if (filename == FileArchives[i]->getFileList()->getPath())
                        return removeFileArchive(i);
        }
        _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
        return false;
}
 
Thanks!
CuteAlien wrote:coders are well-known creatures of the night
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Strange, we have a regression test which actually does exactly that. And so far this test runs through without problems. Did this happen with SVN/trunk version, or the official 1.7.2 release?
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Post by stefbuet »

I'm using 1.7.1 but I checked the 1.7.2 and SVN : it's the same.
Archives are put in the archives list with their absolute path and the removeFileArchive is not converting the argument path to absolute before comparing it.
CuteAlien wrote:coders are well-known creatures of the night
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: fs::removeFileArchive fails

Post by hybrid »

Yes, you're right. I've now changed the API docs to make sure everyone notes the problems that might arise from using a relative path name (or the things one has to remember at least). And I've added a proper test case in the regression. BEfore, we only removed the archives by index, which of course will always work.
Post Reply