[LayaAir 2.0]Laya.loader.load(xx) 当地址""的时候,会报错。

laya 引擎是2.5的
 
  
Laya.loader.load(cg_url,Laya.Handler.create(this,()=>{
            let tur:Laya.Texture = Laya.loader.getRes(cg_url);
            if(tur)img_cg.graphics.drawImage(tur)
        }),null,Laya.Loader.IMAGE); 
 

这段代码, 当 cg_url等于“”的时候,底层判断会走到这个接口下面 this.onLoaded(null)

 
load(url, type = null, cache = true, group = null, ignoreCache = false, useWorkerLoader = ILaya.WorkerLoader.enable) {
            if (!url) {
                this.onLoaded(null);
                return;
            } 
 
 

然后进到this.onLoaded(null)
 

onLoaded(data = null) {
            var type = this._type;
            if (type == Loader.PLFB) {
                this.parsePLFBData(data);
                this.complete(data);
            }
            else if (type == Loader.PLF) {
                this.parsePLFData(data);
                this.complete(data);
            }
            else if (type === Loader.IMAGE) {
                let tex;
                if (data instanceof ArrayBuffer) {
                    var ext = Utils.getFileExtension(this._url);
                    let format;
                    switch (ext) {
                        case "ktx":
                            format = exports.TextureFormat.ETC1RGB;
                            break;
                        case "pvr":
                            format = exports.TextureFormat.PVRTCRGBA_4BPPV;
                            break;
                        default: {
                            console.error('unknown format', ext);
                            return;
                        }
                    }
                    tex = new Texture2D(0, 0, format, false, false);
                    tex.wrapModeU = exports.WarpMode.Clamp;
                    tex.wrapModeV = exports.WarpMode.Clamp;
                    tex.setCompressData(data);
                    tex._setCreateURL(this.url);
                }
                else if (!(data instanceof Texture2D)) {
                    tex = new Texture2D(data.width, data.height, 1, false, false);
                    tex.wrapModeU = exports.WarpMode.Clamp;
                    tex.wrapModeV = exports.WarpMode.Clamp;
                    tex.loadImageSource(data, true);
                    tex._setCreateURL(data.src);
                }
                else {
                    tex = data;
                }
                var texture = new Texture(tex);
                texture.url = this._url;
                this.complete(texture);
            }
            else if (type === Loader.SOUND || type === "nativeimage") {
                this.complete(data);
            }
            else if (type === "htmlimage") {
                let tex = new Texture2D(data.width, data.height, 1, false, false);
                tex.wrapModeU = exports.WarpMode.Clamp;
                tex.wrapModeV = exports.WarpMode.Clamp;
                tex.loadImageSource(data, true);
                tex._setCreateURL(data.src);
                this.complete(tex);
            }
            else if (type === Loader.ATLAS) {
                if (data.frames) {
                    var toloadPics = ;
                    if (!this._data) {
                        this._data = data;
                        if (data.meta && data.meta.image) {
                            toloadPics = data.meta.image.split(",");
                            var split = this._url.indexOf("/") >= 0 ? "/" : "\\";
                            var idx = this._url.lastIndexOf(split);
                            var folderPath = idx >= 0 ? this._url.substr(0, idx + 1) : "";
                            var changeType = null;
                            if (Browser.onAndroid && data.meta.compressTextureAndroid) {
                                changeType = ".ktx";
                            }
                            if (Browser.onIOS && data.meta.compressTextureIOS) {
                                changeType = ".pvr";
                            }
                            for (var i = 0, len = toloadPics.length; i < len; i++) {
                                if (changeType) {
                                    toloadPics = folderPath + toloadPics.replace(".png", changeType);
                                }
                                else {
                                    toloadPics = folderPath + toloadPics;
                                }
                            }
                        }
                        else {
                            toloadPics = [this._url.replace(".json", ".png")];
                        }
                        toloadPics.reverse();
                        data.toLoads = toloadPics;
                        data.pics = ;
                    }
                    this.event(Event.PROGRESS, 0.3 + 1 / toloadPics.length * 0.6);
                    return this._loadResourceFilter(Loader.IMAGE, URL.formatURL(toloadPics.pop()));
                }
                else {
                    if (!(data instanceof Texture2D)) {
                        if (data instanceof ArrayBuffer) {
                            let url = this._http.url;
                            var ext = Utils.getFileExtension(url);
                            let format;
                            switch (ext) {
                                case "ktx":
                                    format = exports.TextureFormat.ETC1RGB;
                                    break;
                                case "pvr":
                                    format = exports.TextureFormat.PVRTCRGBA_4BPPV;
                                    break;
                                default: {
                                    console.error('unknown format', ext);
                                    return;
                                }
                            }
                            let tex = new Texture2D(0, 0, format, false, false);
                            tex.wrapModeU = exports.WarpMode.Clamp;
                            tex.wrapModeV = exports.WarpMode.Clamp;
                            tex.setCompressData(data);
                            tex._setCreateURL(url);
                            data = tex;
                        }
                        else {
                            let tex = new Texture2D(data.width, data.height, 1, false, false);
                            tex.wrapModeU = BaseTexture.WARPMODE_CLAMP;
                            tex.wrapModeV = BaseTexture.WARPMODE_CLAMP;
                            tex.loadImageSource(data, true);
                            tex._setCreateURL(data.src);
                            data = tex;
                        }
                    }
                    this._data.pics.push(data);
                    if (this._data.toLoads.length > 0) {
                        this.event(Event.PROGRESS, 0.3 + 1 / this._data.toLoads.length * 0.6);
                        return this._loadResourceFilter(Loader.IMAGE, this._data.toLoads.pop());
                    }
                    var frames = this._data.frames;
                    var cleanUrl = this._url.split("?")[0];
                    var directory = (this._data.meta && this._data.meta.prefix) ? this._data.meta.prefix : cleanUrl.substring(0, cleanUrl.lastIndexOf(".")) + "/";
                    var pics = this._data.pics;
                    var atlasURL = URL.formatURL(this._url);
                    var map = Loader.atlasMap[atlasURL] || (Loader.atlasMap[atlasURL] = );
                    map.dir = directory;
                    var scaleRate = 1;
                    if (this._data.meta && this._data.meta.scale && this._data.meta.scale != 1) {
                        scaleRate = parseFloat(this._data.meta.scale);
                        for (var name in frames) {
                            var obj = frames[name];
                            var tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
                            var url = URL.formatURL(directory + name);
                            tPic.scaleRate = scaleRate;
                            var tTexture;
                            tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
                            Loader.cacheTexture(url, tTexture);
                            tTexture.url = url;
                            map.push(url);
                        }
                    }
                    else {
                        for (name in frames) {
                            obj = frames[name];
                            tPic = pics[obj.frame.idx ? obj.frame.idx : 0];
                            url = URL.formatURL(directory + name);
                            tTexture = Texture._create(tPic, obj.frame.x, obj.frame.y, obj.frame.w, obj.frame.h, obj.spriteSourceSize.x, obj.spriteSourceSize.y, obj.sourceSize.w, obj.sourceSize.h, Loader.getRes(url));
                            Loader.cacheTexture(url, tTexture);
                            tTexture.url = url;
                            map.push(url);
                        }
                    }
                    delete this._data.pics;
                    this.complete(this._data);
                }
            }
            else if (type === Loader.FONT) {
                if (!data._source) {
                    this._data = data;
                    this.event(Event.PROGRESS, 0.5);
                    return this._loadResourceFilter(Loader.IMAGE, this._url.replace(".fnt", ".png"));
                }
                else {
                    var bFont = new BitmapFont();
                    bFont.parseFont(this._data, new Texture(data));
                    var tArr = this._url.split(".fnt")[0].split("/");
                    var fontName = tArr[tArr.length - 1];
                    Text.registerBitmapFont(fontName, bFont);
                    this._data = bFont;
                    this.complete(this._data);
                }
            }
            else if (type === Loader.PREFAB) {
                var prefab = new Prefab();
                prefab.json = data;
                this.complete(prefab);
            }
            else {
                this.complete(data);
 

            }可以看到 这时候进来的data=null,  当type 有值的时候随便走进一个方法就会报错。我的代码就是走到了这个方法里面
else if (!(data instanceof Texture2D)) {
                    tex = new Texture2D(data.width, data.height, 1, false, false);
                    tex.wrapModeU = exports.WarpMode.Clamp;
                    tex.wrapModeV = exports.WarpMode.Clamp;
                    tex.loadImageSource(data, true);
                    tex._setCreateURL(data.src);
                }
 
 
[i][i]dada=null  data,width 就报错了。[/i][/i]
已邀请:

要回复问题请先

商务合作
商务合作