【求助】cc.loader.load加载图片completeCallback没有调用

我调用cc.loader.load加载原生的本地图片资源,
如果图片存在,load方法能正确回调completeCallback
如果图片不存在,不会回调completeCallback
从log日志中看到这样的错误日志:
E/jswrapper: [ERROR] (D:/CocosCreator/resources/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_global.cpp, 786): initWithImageFile: /storage/emulated/0/DiscoverLand/10/gameRes/gameName.png failed!

我的逻辑需要在出现错误时,我在completeCallback回调中执行出错的逻辑,但现在是不能的。

下面是我的逻辑代码,图片不存在时,
回调中的console.log(“setImageRes 换肤 filePath:” + filePath + “,err:”+err)日志是没有打印出来的。

function(sprite,imageName,callback){
let filePath = nativeGameResDir + imageName+".png";
console.log(“setImageRes 换肤 filePath:” + filePath);
cc.loader.load(filePath, function (err, texture) {
console.log(“setImageRes 换肤 filePath:” + filePath + “,err:”+err);
if(typeof err == “undefined” || err == null || err == “” ){
sprite.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
} else if(callback != null){
callback(err,sprite,imageName);
}
});
}
请大家帮忙看一下是我代码的问题,还是creator的BUG。以及怎样解决

游戏是运行在Android平台的

哪一个creator版本?我这边用2.0.5试了下可以正常调用callback

hello这个资源是不存在的一个资源

我的Creator版本是2.0.2

你的路径识别成网络图片了吧,我的路径是本地图片的路径

我这里如果用非本地的不存在的资源,也能正确回调,用本地不存在的就不能

加载本地资源,2.0.2版本同样回进行completeCallback的调用。

    start () {
        cc.loader.loadRes("/storage/emulated/0/DiscoverLand/10/gameRes/gameName.png", (error, item) => {
            cc.log(error.errorMessage, "status:" , error.status);
            cc.log(item);
        });
    },

是在Android平台下吗?

我在android平台和web下面都测了,都没问题啊

是load()方法哦,不是loadRes方法

load在adroid下不存在文件时,确实不会调用callback,具体可以查看jsb_global.cpp文件

如果要找不到文件时也进行callback的调用,可以定制一下引擎,在return fase前调用callback,可以参考:

            se::ValueArray seArgs;
            callbackVal.toObject()->call(seArgs, nullptr);
1赞

非常感谢高效的回复。
我这边写了js调用原生的方法进行判断文件是否存在,来解决这个问题了