Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Prevent
onRemove
/onDetach
being called for initial Gesture D…
…etector addition (#2653) This fixes: #2647 Reverts: #2602 OBE: #2650 To be clear, the memory leak issue is not addressed because it is not a Flame issue. Flame properly calls the `onRemove` event and if it is needed to pass that on to children, users should do as documented: https://docs.flame-engine.org/latest/flame/game.html#lifecycle. So if you are using `GameWidget.controlled`, add a tappable component and then remove the game, the lifecycle looks like: ``` flutter: onLoad flutter: mount flutter: onMount flutter: attach flutter: add has_tappable_components flutter: refreshWidget // Remove Game flutter: detach flutter: removeGameStateListener flutter: onRemove flutter: remove ``` If you do not use `GameWidget.controlled`, add a tappable component and then remove the game, the lifecycle looks like: ``` flutter: onLoad flutter: mount flutter: onMount flutter: attach flutter: add has_tappable_components flutter: refreshWidget // Remove Game flutter: detach flutter: removeGameStateListener flutter: onRemove flutter: remove ``` If you do not use `GameWidget.controlled`, do not add a tappable component and then remove the game, the lifecycle looks like: ``` flutter: onLoadFuture flutter: mount flutter: onMount flutter: attach // Remove Game flutter: detach flutter: removeGameStateListener flutter: onRemove flutter: remove ``` Previously, the lifecycle would look like: ``` flutter: onLoad flutter: mount flutter: onMount flutter: attach flutter: add has_tappable_components flutter: refreshWidget flutter: detach // These unnecessary calls have been eliminated flutter: removeGameStateListener // These unnecessary calls have been eliminated flutter: onRemove // These unnecessary calls have been eliminated flutter: attach // Remove Game flutter: detach flutter: removeGameStateListener flutter: onRemove flutter: remove ``` I have updated the below diagram for those who may need it in the future: ![Flame and Flutter Events Fixed](https://github.com/flame-engine/flame/assets/17042581/1d98bdaf-db13-4e2c-b0a6-74da2ada89f3)
- Loading branch information