Skip to content

Label 纹理释放问题 #16721

Closed
Closed

Description

@G0115

Cocos Creator version

3.8.0

System information

Windows 10 Editor

Issue description

当某个节点同时存在 Label 与 LabelOutline 组件,且对 LabelOutline 属性进行过修改,并且该节点一直没有激活(创建后node.active设置false);则该节点被销毁时会出现纹理缓存没有正确释放的问题。

Relevant error log output

No response

Steps to reproduce

问题分析

  • 当 LabelOutline 的属性发生修改时,会触发 Label 的 _applyFontTexture 方法并创建出新的纹理对象(此处的Label使用默认的缓存模式);

  • 节点的active一直为false,则组件的 _objFlags 不会包含 IsOnLoadCalled 状态(即组件的onLoad方法没有被调用过);

  • 节点销毁时,只有包含 IsOnLoadCalled 状态的组件才会触发 onDestroy 方法。

  • Label 组件在 onDestroy 回调方法中对纹理缓存进行释放。

解决方案

  • 在 Label 中重写 _onPreDestroy 方法,判断是否包含 IsOnLoadCalled 状态:

    • 包含,直接调用 super._onPreDestroy()

    • 不包含,尝试进行纹理缓存的释放。

Minimal reproduction project

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions