Null check operator used on a null value upon switching routes quickly in succession
What happened?
I'm never able to replace this on the desktop, but when I am spamming between scenes with multiple fingers on my phone, this is easily replicated and causes a App Not Responding issue. It seems likely that on a day to day use, a user may possibly swap between tabs quickly and experience this same error.
From the stack trace, It seems like _parent's value changed to null right after the null check to _parent, and before the accessor, causing the null check error.
What do you expect?
App not freezing when swapping between routes super quickly in succession.
How can we reproduce this?
Create a couple of buttons that switches between routes, and spam them with multiple fingers quickly in succession. Eventually something will be tried to be removed when it can't.
What steps should take to fix this?
Hold a reference to _parent before accessing it in the following calls. Since _parent is an instance variable, it can be changed to null between the null check and the next access occurrance.
Do have an example of where the bug occurs?
No response
Relevant log output
flutter: Navigating guild_scene_v2 > world_scene_v2
flutter: {3: true}
flutter: Adding coin flip merchant 3
flutter: Null check operator used on a null value
flutter: #0 Component._remove.<anonymous closure> (package:flame/src/components/core/component.dart:1056)
flutter: #1 Iterable.every (dart:core/iterable.dart:446)
flutter: #2 Component.propagateToChildren (package:flame/src/components/core/component.dart:405)
flutter: #3 Component._remove (package:flame/src/components/core/component.dart:1046)
flutter: #4 Component.handleLifecycleEventMove (package:flame/src/components/core/component.dart:907)
flutter: #5 ComponentTreeRoot.processLifecycleEvents (package:flame/src/components/core/component_tree_root.dart:137)
flutter: #6 FlameGame.updateTree (package:flame/src/game/flame_game.dart:158)
flutter: #7 FlameGame.update (package:flame/src/game/flame_game.dart:152)
flutter: #8 IdleHorizons.update (package:idlehorizons/src/idle_horizons.dart:230)
flutter: #9 GameRenderBox.gameLoopCallback (package:flame/src/game/game_render_box.dart:121)
flutter: #10 GameLoop._tick (package:flame/src/game/game_loop.dart:46)
flutter: #11 Ticker._tick (package:flutter/src/scheduler/ticker.dart:269)
flutter: #12 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1438)
flutter: #13 SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1269)
flutter: #14 _LinkedHashMapMixin.forEach (dart:_compact_hash:764)
flutter: #15 SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1267)
flutter: #16 SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:1183)
flutter: #17 _invoke1 (dart:ui/hooks.dart:347)
flutter: #18 PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:426)
flutter: #19 _beginFrame (dart:ui/hooks.dart:292)
flutter: Popped to store_scene_v2
flutter: Navigating world_scene_v2 > store_scene_v2
Execute in a terminal and put output into the code block below
Output of: flutter doctor -v
[✓] Flutter (Channel stable, 3.32.2, on macOS 15.1 24B2083 darwin-arm64, locale en-US) [1,672ms]
• Flutter version 3.32.2 on channel stable at /Users/macbook/development/flutter
• Upstream repository [email protected]:flutter/flutter.git
• Framework revision 8defaa71a7 (10 days ago), 2025-06-04 11:02:51 -0700
• Engine revision 1091508939
• Dart version 3.8.1
• DevTools version 2.45.1
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,683ms]
• Android SDK at /Users/macbook/Library/Android/sdk
✗ cmdline-tools component is missing.
Try installing or updating Android Studio.
Alternatively, download the tools from https://developer.android.com/studio#command-line-tools-only and make
sure to set the ANDROID_HOME environment variable.
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/to/macos-android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 16.1) [3.7s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [228ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.2) [227ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
[✓] IntelliJ IDEA Ultimate Edition (version 2025.1.2) [224ms]
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 85.3.2
• Dart plugin version 251.25410.28
Affected platforms
iOS, Android
Other information
No response
Are you interested in working on a PR for this?
- [ ] I want to work on this
Ah, good catch. Could you try this branch (haven't tested it yet 😅):
dependency_overrides:
flame:
git:
url: https://github.com/flame-engine/flame.git
ref: fix/pass-in-intended-parent
path: packages/flame
That looks like it did the trick :) Was unable to trigger it at all after spamming it.