-
-
Notifications
You must be signed in to change notification settings - Fork 908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Check for removing state while adding a child #3050
Conversation
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you describe in the PR description what the PR solves?
What happens when enqueeing an add when the parent is removing? Shouldn't it be reconciled at mounting still? 🤔
Due to the sequence of the queue, the child's flame/packages/flame/lib/src/components/core/component_tree_root.dart Lines 109 to 110 in 892052b
So in the next iteration when the parent's re-add event was encountered, it was getting skipped here: flame/packages/flame/lib/src/components/core/component_tree_root.dart Lines 85 to 88 in 892052b
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
Posting the MRE just in case anyone is interested: class RemoveAddGame extends FlameGame with HasKeyboardHandlerComponents {
final RectangleComponent rectangle = RectangleComponent(
size: Vector2.all(100),
position: Vector2.all(100),
);
@override
Future<void> onLoad() async {
await add(rectangle);
}
@override
KeyEventResult onKeyEvent(
KeyEvent event,
Set<LogicalKeyboardKey> keysPressed,
) {
if (event is! KeyDownEvent) {
return KeyEventResult.handled;
}
if (event.logicalKey == LogicalKeyboardKey.keyA) {
add(rectangle);
} else if (event.logicalKey == LogicalKeyboardKey.keyR) {
rectangle.removeFromParent();
}
rectangle.add(Component());
return super.onKeyEvent(event, keysPressed);
}
} |
Description
Adding a child component to a parent which is in
removing
state, caused the lifecycle processing to go into a cyclic dependency when the parent is re-added. It happens because, while processing the lifecycle events, child's add event causes itself and the parent to get added to the blocked list. As a result of this, when the parent's add event is processed next, it gets skipped due to being in the blocked list.This PR makes sure that the child does not get enqueued when parent is about to be removed.
Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues
NA