Ogre的文件读取是使用的标准库的io库读取的,众所周知的是,在vs2005是存在着bug的。
因此想要一劳永逸的解决这个办法唯有去修改Ogre的源代码,以下为修改方法:
打开OgreFileSystem.cpp文件,找到FileSystemArchive::open方法,使用以下代码替换之:
 DataStreamPtr FileSystemArchive::open(const String& filename) const
DataStreamPtr FileSystemArchive::open(const String& filename) const

 
     {
{
 String full_path = concatenate_path(mName, filename);
        String full_path = concatenate_path(mName, filename);

 // Use filesystem to determine size
        // Use filesystem to determine size 
 // (quicker than streaming to the end and back)
        // (quicker than streaming to the end and back)
 struct stat tagStat;
        struct stat tagStat;
 int ret = stat(full_path.c_str(), &tagStat);
        int ret = stat(full_path.c_str(), &tagStat);
 assert(ret == 0 && "Problem getting file size" );
        assert(ret == 0 && "Problem getting file size" );

 // Always open in binary mode
        // Always open in binary mode
 static std::vector<wchar_t>    s_wchar_buf((size_t)128);
        static std::vector<wchar_t>    s_wchar_buf((size_t)128);
 size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
        size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
 if (s_wchar_buf.size() < lengthUnicode + 1)
        if (s_wchar_buf.size() < lengthUnicode + 1)

 
         {
{
 s_wchar_buf.resize(lengthUnicode * 2);
            s_wchar_buf.resize(lengthUnicode * 2);
 }
        }
 wchar_t* szUnicode = &s_wchar_buf[0];
        wchar_t* szUnicode = &s_wchar_buf[0];
 MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
        MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
 szUnicode[lengthUnicode] = 0;
        szUnicode[lengthUnicode] = 0;
 std::ifstream* origStream = new std::ifstream();
        std::ifstream* origStream = new std::ifstream();
 origStream->open(szUnicode, std::ios::in | std::ios::binary);
        origStream->open(szUnicode, std::ios::in | std::ios::binary);

 // Should check ensure open succeeded, in case fail for some reason.
        // Should check ensure open succeeded, in case fail for some reason.
 if (origStream->fail())
        if (origStream->fail())

 
         {
{
 delete origStream;
            delete origStream;
 OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
            OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
 "Cannot open file: " + filename,
                "Cannot open file: " + filename,
 "FileSystemArchive::open");
                "FileSystemArchive::open");
 }
        }


 /**//// Construct return stream, tell it to delete on destroy
        /**//// Construct return stream, tell it to delete on destroy
 FileStreamDataStream* stream = new FileStreamDataStream(filename,
        FileStreamDataStream* stream = new FileStreamDataStream(filename,
 origStream, tagStat.st_size, true);
            origStream, tagStat.st_size, true);
 return DataStreamPtr(stream);
        return DataStreamPtr(stream);
 }
    }
 因此想要一劳永逸的解决这个办法唯有去修改Ogre的源代码,以下为修改方法:
打开OgreFileSystem.cpp文件,找到FileSystemArchive::open方法,使用以下代码替换之:
 DataStreamPtr FileSystemArchive::open(const String& filename) const
DataStreamPtr FileSystemArchive::open(const String& filename) const
 
     {
{ String full_path = concatenate_path(mName, filename);
        String full_path = concatenate_path(mName, filename);
 // Use filesystem to determine size
        // Use filesystem to determine size  // (quicker than streaming to the end and back)
        // (quicker than streaming to the end and back) struct stat tagStat;
        struct stat tagStat; int ret = stat(full_path.c_str(), &tagStat);
        int ret = stat(full_path.c_str(), &tagStat); assert(ret == 0 && "Problem getting file size" );
        assert(ret == 0 && "Problem getting file size" );
 // Always open in binary mode
        // Always open in binary mode static std::vector<wchar_t>    s_wchar_buf((size_t)128);
        static std::vector<wchar_t>    s_wchar_buf((size_t)128); size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
        size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0); if (s_wchar_buf.size() < lengthUnicode + 1)
        if (s_wchar_buf.size() < lengthUnicode + 1)
 
         {
{ s_wchar_buf.resize(lengthUnicode * 2);
            s_wchar_buf.resize(lengthUnicode * 2); }
        } wchar_t* szUnicode = &s_wchar_buf[0];
        wchar_t* szUnicode = &s_wchar_buf[0]; MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
        MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode); szUnicode[lengthUnicode] = 0;
        szUnicode[lengthUnicode] = 0; std::ifstream* origStream = new std::ifstream();
        std::ifstream* origStream = new std::ifstream(); origStream->open(szUnicode, std::ios::in | std::ios::binary);
        origStream->open(szUnicode, std::ios::in | std::ios::binary);
 // Should check ensure open succeeded, in case fail for some reason.
        // Should check ensure open succeeded, in case fail for some reason. if (origStream->fail())
        if (origStream->fail())
 
         {
{ delete origStream;
            delete origStream; OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
            OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Cannot open file: " + filename,
                "Cannot open file: " + filename, "FileSystemArchive::open");
                "FileSystemArchive::open"); }
        }

 /**//// Construct return stream, tell it to delete on destroy
        /**//// Construct return stream, tell it to delete on destroy FileStreamDataStream* stream = new FileStreamDataStream(filename,
        FileStreamDataStream* stream = new FileStreamDataStream(filename, origStream, tagStat.st_size, true);
            origStream, tagStat.st_size, true); return DataStreamPtr(stream);
        return DataStreamPtr(stream); }
    }posted on 2008-12-09 03:42 杨粼波 阅读(957) 评论(2)  编辑 收藏 引用 
Feedback