Fix label inactivation without calling destroy to release resources
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 casesafterward. - [ ] 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.
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 更新渲染相关数据。
I don't understand why it can fix the issue.
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.
Got it, i think it is better to add override for the function. And please fix the CI error.
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();
}
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