cocos2dx 3.x fullPathForFilename及isFileExist在ios/mac下与win32下行为不同
一,fullPathForFilename
项目先开发了ios/mac版本,这两天想把win32工程也配好,但遇到了部分资源无法正确找到的问题。
进一步观察发现,对于那些找不到的资源路径,fullPathForFilename将传入的短路径直接原样返回,而不是返回全路径。
查看fullPathForFilename的实现代码,有这样一段:
// FIXME: Should it return nullptr ? or an empty string ?
// The file wasn't found, return the file name passed in.
return filename;
即当前的处理是如果路径找不到,就将参数原样返回。
因此初步确定是因为路径没找到造成的,那么为什么找不到呢?
在fullPathForFilename的实现内打断点,查看_searchPathArray的值,发现其中的路径是对的:

但其中fullpath = this->getPathForFilename(newFilename, resolutionIt, searchIt)一句返回的fullpath却是空。
于是跟到getPathForFilename中断点,发现在其中path = getFullPathForDirectoryAndFilename(path, file)一句之前构造的路径都是与预期相符的,而此句返回的path却是空字符串。
于是再跟到getFullPathForDirectoryAndFilename中,发现其中有下面代码:
// if the file doesn't exist, return an empty string
if (!isFileExistInternal(ret)) {
ret = "";
}
于是明白了,原来是ios/mac上的isFileExistInternal与win32上的isFileExistInternal行为不一致,在ios/mac上,isFileExistInternal无论传入文件路径还是文件夹路径,只要路径存在,都会返回true;而在win32平台上,isFileExistInternal只有传入的是文件路径且文件存在时才会返回true,而如果传入文件夹路径,则总会返回false。我在项目中使用了fullPathForFilename去获得文件夹的全路径,于是在ios/mac下能正常工作,但在win32上不能正常工作。
一个简单的方法是直接将getFullPathForDirectoryAndFilename中那段代码改成:
// if the file doesn't exist, return an empty string
if (!isFileExistInternal(ret)
&&!isDirectoryExistInternal(ret)//added [yang chao]
) {
ret = "";
}
这样win32上fullPathForFilename的行为就与ios/mac上相同了。
二,isFileExist
isFileExist中使用了isFileExistInternal函数,所以isFileExist的行为在win32上也与ios/mac上不一致。在ios/mac上,判断文件或文件夹是否存在都可以用isFileExist函数,而在win32平台上isFileExist只能判断文件是否存在,如果想判断文件夹是否存在,要用isDirectoryExist函数。
cocos2dx 3.x fullPathForFilename及isFileExist在ios/mac下与win32下行为不同的更多相关文章
- cocos2d-x 3.x游戏开发学习笔记(1)--mac下配置cocos2d-x 3.x开发环境
打开用户文件夹下.bash_profile文件,配置环境 vim ~/.bash_profile //按键i,进行插入编辑(假设输错d进行删除一行) 环境配置过程例如以下: 1.首先配置下androi ...
- Mac下搭建quick cocos2d-x编译环境
一. 我知道在你的电脑中一定已经安装好了Xcode(没有自己下载去吧),打开Xcode,开启"偏好设置"对话框(commond + ,).假设打开之后出现的是这种一个对话框,那么直 ...
- cocos2dx 2.2.3 xcode5.0,新mac项目错误
cocos2dx 2.2.3 xcode5.0,新建mac项目报错 Undefined symbols for architecture x86_64: "cocos2d::extens ...
- MAC 下将libpomelo连接到cocos2d-x
摘要:借助GYP将libpomelo连接到Cocos2d-x项目并使项目能与服务端成功连接. 配置:OS X 10.9.4 + Xcode 6.0 + Cocos2d-x-3.2 一.部署GYP(Ge ...
- Mac下编译libpomelo静态库,并在cocos2dx项目中引用
最近在学习cocos2dx的过程中需要和服务器进行交互,所以这几天在学习libpomelo静态库的编译和使用.之前在windows系统下编译libpomelo,并在VS中引入比较顺利:但是,目前对Ma ...
- 中文 iOS/Mac 开发博客列表
中文 iOS/Mac 开发博客列表 博客地址 RSS地址 OneV's Den http://onevcat.com/atom.xml 一只魔法师的工坊 http://blog.ibireme.com ...
- 谈iOS抓包:Mac下好用的HTTP/HTTPS抓包工具Charles
在Mac下做开发,用Fiddler抓包由于离不开Windows比较痛苦,还好有Charles,到官网http://www.charlesproxy.com/可下载到最新版本(若不支持rMBP可拖到Re ...
- 中文 iOS/Mac 开发博客列表(转)
转自https://github.com/tangqiaoboy/iOSBlogCN 中文 iOS/Mac 开发博客列表 本博客列表会不断更新维护,如果有推荐的博客,请到此处提交博客信息. 本博客列表 ...
- 手把手教你ARC——iOS/Mac开发ARC入门和使用
转载自:http://www.onevcat.com/2012/06/arc-hand-by-hand/ 本文部分实例取自iOS 5 Toturail一书中关于ARC的教程和公开内容,仅用于技术交流和 ...
随机推荐
- [Unity-6] GameObject有时候渲染不出来
问题描写叙述:在做游戏的过程中遇到了这样一个问题.一个怪物,假设让他出如今屏幕的中央是没问题的,可是让他出如今屏幕的边缘的位置发现他没有出现. 问题原因:经过检查发现,我给这个GameObject加入 ...
- debug输出rect,size和point的宏
#define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, ...
- Android开发之发送邮件功能的实现(源码分享)
Android开发中可能会碰到怎样发送邮件的困扰,之前我也查了相关的文档,博友们也分享了不少的发送邮件的办法.总共同拥有3种把,我细致阅读了下,发现有的讲的太过复杂跟麻烦,不够清晰.我今天就来分享下我 ...
- vue 数组 新增元素 响应式原理 7种方法
1.问题 思考一个问题,以下代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Caffe源代码中Solver文件分析
Caffe源代码(caffe version commit: 09868ac , date: 2015.08.15)中有一些重要的头文件,这里介绍下include/caffe/solver.hpp文件 ...
- component和bean区别
@Component and @Bean do two quite different things, and shouldn't be confused. @Component (and @Serv ...
- exception PLS-00103: Encountered the symbol "(" when expecting one of the following:
exception PLS-00103: Encountered the symbol "(" when expecting one of the following: Cre ...
- PmExceptionController
package main.java.com.zte.controller.system; import java.util.ArrayList; import java.util.List; impo ...
- smack 4.1.2+openfire 3.10.2i
openfire 和以往版本号配置没有多大差别就不具体介绍了,网上搜会有一大堆的图解 以下主要说一下smack 4.1.2 的开发使用,在网上看了好多文章包含stackoverflow的都没有4.1以 ...
- 如何使php页面中不再出现NOTICE和DEPRECATED的错误提示
在php.ini配置文件中修改: error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED 亲测有效,拿去用吧