-
-
Notifications
You must be signed in to change notification settings - Fork 915
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: Prevent onRemove
/onDetach
being called for initial Gesture Detector addition
#2653
Conversation
onRemove
being called for initial Gesture Detector addition
I think this can be done in a simpler manner by using the @internal
bool isInternalRefresh = false;
@internal
void refreshWidget() {
isInternalRefresh = true;
gameStateListeners.forEach((callback) => callback());
isInternalRefresh = false;
} What do you think?
Shouldn't the last attach call here also be removed? |
@spydon This was my original plan of attack and I even went a step further by trying to identify the callback to check and see if it was a gesture detector, but the callback name is an internal id to Flutter (or maybe I don't know enough to get a simpleName or such).
I am open to this way so any pointers are greatly appreciated! As far as the last attach, I thought about that but with what I implemented, GRB was being set to null, so then it wouldn't be available to read the flag in Edit: And I would say, I was originally looking at stopping the events in the GRB, but learned that is not a smart approach, so technically, there should be no reason why the flag cannot exist in Game as all detectors have a game reference. Edit2: I have implemented a version of your suggestion and tested everything to confirm it still works as anticipated. All tests pass and the event lifecycle now removes the extra |
onRemove
being called for initial Gesture Detector additiononRemove
/onDetach
being called for initial Gesture Detector addition
…r/flame into flameLifecycleFixes
Co-authored-by: Lukas Klingsbo <[email protected]>
Co-authored-by: Lukas Klingsbo <[email protected]>
Analyzer failed after direct committing your changes from GitHub. When pulled, its passing local. Let me update branch and see what happens. |
How strange, the warning wasn't even about any code that you have touched. 🤷♂️ |
Yeah, I pulled the last updates down, but I can't figure out what is going on. I can't see the logs or I don't know how to see the Analyzer logs in GitHub. What am I missing on this? OH! The little triangle. Ok, I see the issue. So with your suggested name change, it just needed to be updated in the other file. |
Yeah that was one thing, but there also was a warning about a file in Jenny. Let's see if that warning pops up again now. |
…lame-engine#2659) This adds, imo, the missing piece in the event lifecycle based on all the other lifecycle work I have been doing. Currently, when dispose is called in game_widget.dart, it calls disposeCurrentGame which has the call for onRemove, at issue though is, disposeCurrentGame is also called by didUpdateWidget if the oldWidget.game != widget.game. It may not be needed, but I feel like because FlameGame is inherently a stateless set of widgets (children of the LeafRenderObjectWidget), the hook for onRemove is muddled with what is NOT actually a dispose event. So my thought is, introduce the onDispose method to game which gets called by making disposeCurrentGame({isDispose = false}) then in the actual overridden dispose method, pass that as true, so we can then call currentGame.onDispose() after the call to currentGame.onRemove().
class _RecordingDialogueViewAsMixin extends _SomeOtherBaseClass
with DialogueView {
_RecordingDialogueViewAsMixin([this.waitDuration = Duration.zero]);
final List<String> events = [];
final Duration waitDuration; This is the warning. |
Co-authored-by: Lukas Klingsbo <[email protected]>
Co-authored-by: Lukas Klingsbo <[email protected]>
…r/flame into flameLifecycleFixes
Description
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:If you do not use
GameWidget.controlled
, add a tappable component and then remove the game, the lifecycle looks like:If you do not use
GameWidget.controlled
, do not add a tappable component and then remove the game, the lifecycle looks like:Previously, the lifecycle would look like:
I have updated the below diagram for those who may need it in the future:
Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues