cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

Fix label inactivation without calling destroy to release resources

Open qiuguohua opened this issue 1 year ago • 4 comments

Re: #

Changelog

https://github.com/cocos/cocos-engine/issues/16721


Continuous Integration

This pull request:

  • [ ] needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • [ ] does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • [ ] changes public API, and have ensured backward compatibility with deprecated features.
  • [ ] affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • [ ] affects file structure of the build package or build configuration which requires user project upgrade.
  • [ ] introduces breaking changes, please list all changes, affected features and the scope of violation.

qiuguohua avatar Feb 23 '24 00:02 qiuguohua

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -3342,8 +3342,9 @@
         protected _textRenderData: __private._cocos_2d_assembler_label_text_output_data__TextOutputRenderData | null;
         protected _textLayoutData: __private._cocos_2d_assembler_label_text_output_data__TextOutputLayoutData | null;
         constructor();
         onEnable(): void;
+        _onPreDestroy(): void;
         onDestroy(): void;
         /**
          * @en update render data.
          * @zh 更新渲染相关数据。

github-actions[bot] avatar Feb 23 '24 01:02 github-actions[bot]

I don't understand why it can fix the issue.

minggo avatar Feb 23 '24 01:02 minggo

I don't understand why it can fix the issue.

super._onpredestroy checks to see if _isOnLoadCalled is included, and calls ondestroy if it is.

Here we rewrite _onpredestroy to determine if it contains _isOnLoadCalled, if so, we go directly to the original logic, if not, we release the resources that have already been applied.

qiuguohua avatar Feb 23 '24 02:02 qiuguohua

Got it, i think it is better to add override for the function. And please fix the CI error.

minggo avatar Feb 23 '24 02:02 minggo

After apply this merge request, if the Label component was destroyed before node's first activation, the Label component will not be removed from node, because super._onPreDestroy() will not be called.

Or is the following a better way?

    public _onPreDestroy (): void {
        super._onPreDestroy();

        if (this._isOnLoadCalled) {
            return;
        }
        // If _objFlags does not contain IsOnLoadCalled, it is possible to destroy the ttfSpriteFrame.
        this.destroyTtfSpriteFrame();
    }

huhudage avatar Apr 01 '24 08:04 huhudage

After apply this merge request, if the Label component was destroyed before node's first activation, the Label component will not be removed from node, because super._onPreDestroy() will not be called.

Or is the following a better way?

    public _onPreDestroy (): void {
        super._onPreDestroy();

        if (this._isOnLoadCalled) {
            return;
        }
        // If _objFlags does not contain IsOnLoadCalled, it is possible to destroy the ttfSpriteFrame.
        this.destroyTtfSpriteFrame();
    }

Yes, you're right. I'll fix it later

qiuguohua avatar Apr 01 '24 09:04 qiuguohua