龙骨远程加载内存泄露问题二


龙骨远程加载内存泄露问题二

chrome发现DragonBonesAsset等资源重复加载了

  • 龙骨远程加载
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
preloadRemoteDragonbones(baseUrls, names, callback){
let _t = 0;
for (const key in baseUrls) {
if(this.dragonbonesAssetMaps[names[key]]){ // 判断是否已经加载过了
_t++;
if (_t === baseUrls.length) {
callback(true, 100);
continue;
}
callback(false, 100 * (_t / baseUrls.length));
continue;
}
let baseUrl = baseUrls[key];
let bone = {
bone_ske: baseUrl + "_ske.json",
bone_tex : baseUrl + "_tex.json",
bone_tex_img: baseUrl + "_tex.png"
};
// 远程加载
cc.loader.load([bone.bone_ske, bone.bone_tex, bone.bone_tex_img], (err, results) => {
_t++;
if (!err && !this.dragonbonesAssetMaps[names[key]]){
let _dragonAsset = new dragonBones.DragonBonesAsset();
// @ts-ignore
_dragonAsset._uuid = bone.bone_ske;
_dragonAsset.dragonBonesJson = JSON.stringify(results.getContent(bone.bone_ske));
let _dragonAtlasAsset = new dragonBones.DragonBonesAtlasAsset();
// @ts-ignore
_dragonAtlasAsset._uuid = bone.bone_tex;
_dragonAtlasAsset.atlasJson = JSON.stringify(results.getContent(bone.bone_tex));
_dragonAtlasAsset.texture = results.getContent(bone.bone_tex_img);
// 缓存到map中
let asset = {
dragonAsset: _dragonAsset,
dragonAtlasAsset: _dragonAtlasAsset,
};
this.dragonbonesAssetMaps[names[key]] = asset;
}

if (_t === baseUrls.length) return callback(true, 100);
callback(false, 100 * (_t / baseUrls.length));
});
}
}