Skip to content

Loader.ts中的_load2方法会把内容为空资源也缓存起来 #1820

@talentyao

Description

@talentyao

Loader.ts 版本:3.2.4

_load2方法中存在以下代码,当content==null一样会缓存起来。实际游戏运行中当网络偶尔出现问题时,会出现content为空的情况,但我们期望网络恢复时能正常加载到该资源,但此时缓存已被null的资源占据导致无法加载到有内容的资源,只能退出游戏或者清空对应的缓存才能处理。但是更好的方案是把_load2方法中这段代码

 if (task.options.cache !== false)
                Loader._cacheRes(formattedUrl, content, typeId, main);

  if (content != null && assetLoader.postLoad != null) {
      task.result = content;
      return assetLoader.postLoad(task, content).then(() => {
          task.progress.update(-1, 1);
          task.onComplete.invoke(content);
          return content;
      });
  }

改为:

if (content != null && assetLoader.postLoad != null) {
        
      if (task.options.cache !== false)
                Loader._cacheRes(formattedUrl, content, typeId, main);
      
      task.result = content;
      return assetLoader.postLoad(task, content).then(() => {
          task.progress.update(-1, 1);
          task.onComplete.invoke(content);
          return content;
      });
  }

即:当内容为空时不缓存该资源。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions