Skip to content

Commit c60443f

Browse files
committed
fix(ui):keep destroy widgets out of the widget's active list
1 parent 09b6378 commit c60443f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

cocos/ui/widget-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function align (node: Node, widget: Widget): void {
204204
// TODO: type is hack, Change to the type actually used (Node or BaseNode) when BaseNode complete
205205
function visitNode (node: any): void {
206206
const widget = node.getComponent(Widget);
207-
if (widget && widget.enabled) {
207+
if (widget && widget.enabled && cclegacy.isValid(widget, true)) {
208208
if (DEV) {
209209
widget._validateTargetInDEV();
210210
}

cocos/ui/widget.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ export class Widget extends Component {
852852
}
853853

854854
public onDestroy (): void {
855+
// `onDisable` is skipped when the component was never enabled by the scheduler
856+
// (`IsOnEnableCalled` unset), so unregister here as well.
857+
cclegacy._widgetManager?.remove(this);
855858
this._removeParentEvent();
856859
}
857860

0 commit comments

Comments
 (0)