Fork me on GitHub

OgreSDK_vc8_v1-7-2 sample compile problem

本本上编译的是比较早的ogre3d代码,看到新的ogre3d版本的sample做了修改, 每个例子都弄成dll,想看看怎么样,下了一个来编译,结果出问题了,一个是vc版本问题,下了VS80sp1-KB971090-X86-INTL.exe补丁打上, 另一个是装的directx版本也老了,找不到d3dx9d_42.dll,又下了个DXSDK_Aug09.exe,最后终于ok了,结果运行sample brower时候,TMD出现异常,提示0: fileexception, can not create saveconfig file... ..., 最后只好照着异常提示,看ogre3d的ogreroot.cpp代码,查找问题,终于揪出了元凶:

首先是找到这里:

//ogreroot.cpp

void Root::saveConfig(void)
    {
        if (mConfigFileName.empty ())
            return;

  std::ofstream of(mConfigFileName.c_str()); //这里啦!!!!

        if (!of)  //这里啦!!!!!!!!
            OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Cannot create settings file.",
            "Root::saveConfig");

-----------------------------------------------------------------

‍mConfigFileName----------->

-----------------------------------------------------------

到这里啦:samplecontext.h

virtual void createRoot()
  {
            Ogre::String pluginsPath = Ogre::StringUtil::BLANK;
            #ifndef OGRE_STATIC_LIB
    pluginsPath = mFSLayer->getConfigFilePath("plugins.cfg");
            #endif
   mRoot = OGRE_NEW Ogre::Root(pluginsPath, mFSLayer->getWritablePath("ogre.cfg"),  //这里啦!!!!!!!!
    mFSLayer->getWritablePath("ogre.log"));

--------------------------------------------------------------

‍最后到这里啦:。。。。。。。。

 //就是这里出问题的啦,sample的coder脑子哪有问题,为什么不在sample brower执行文件同目录下,设置ogre.cfg路径!!!

//跑到我的:我的文档下,搞出\Ogre\Cthugha 这鬼东西

//Samples\Browser\src\FileSystemLayerImpl_WIN32.cpp

 void FileSystemLayerImpl::prepareUserHome(const Ogre::String& subdir)
 {

  TCHAR path[MAX_PATH];
  //////////////////////////////////////////////////////////////////////////这是我添加的代码,改变sample code的路径mHomePath到sample brower执行文件目录下
        GetModuleFileName(NULL, path, MAX_PATH);
  TCHAR oemPath[MAX_PATH];
  CharToOem(path, oemPath);
  mHomePath = oemPath;
  return;
  //////////////////////////////////////////////////////////////////////////这是我添加的代码,改变sample code的路径mHomePath到sample brower执行文件目录下

‍不过为什么:我的文档\Ogre\Cthugha 这个路径有问题呢?

原来是:

问题出在std::ofstream of(mConfigFileName.c_str()); //这里啦!!!!

 如果文件的路径中含有中文字符的话这个文件不会被创建也不会被打开,sample coder设置到:D:\我的文档\Ogre\Cthugha, 出问题的。

当然如果不想改prepareUserHome,就设置setlocale(LC_ALL, "chs");支持中文路径

 

最后去享受sample啦!

最后说句感想:无源代码无真相!

if没有查看ogreroot.cpp

my head will be reeling!

 

 

posted @ 2011-04-16 20:50  europelee  阅读(214)  评论(0编辑  收藏  举报