flame icon indicating copy to clipboard operation
flame copied to clipboard

Partially consuming the output of `componentsAtPoint` breaks rendering

Open misha opened this issue 2 years ago • 1 comments

Current bug behavior

I have a game with a red CircleComponent using TapDetector. In the onTapUp callback, I have the following code:

  void onTapUp(TapUpInfo info) {
    componentsAtPoint(info.eventPosition.global)
        .whereType<CircleComponent>()
        .iterator
        .moveNext();
  }

I expected this code to be free of side effects and do basically nothing.

However, if you tap the circle 4 times, the circle goes away.

The critical part appears to be the call to moveNext. The bug does not occur without it.

Expected behavior

The circle should not go away.

Steps to reproduce

Basically what is in the description. I have a repository containing the code here:

https://github.com/misha/flame_debug

Flutter doctor output

$ flutter doctor -v
[✓] Flutter (Channel beta, 3.16.0-0.4.pre, on Ubuntu 22.04.3 LTS
    6.2.0-36-generic, locale en_US.UTF-8)
    • Flutter version 3.16.0-0.4.pre on channel beta at
      /home/misha/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 379c3f4d37 (5 days ago), 2023-11-01 11:34:49 -0700
    • Engine revision abdaabc6dc
    • Dart version 3.2.0 (build 3.2.0-210.4.beta)
    • DevTools version 2.28.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /home/misha/Android/Sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /home/misha/Android/Sdk
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2020.3)
    • Android Studio at /opt/android-studio
    • 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 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.84.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.76.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS
      6.2.0-36-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 118.0.5993.117

[✓] Network resources
    • All expected network resources are available.

• No issues found!

More environment information

  • Flame version: 1.10.1
  • Platform affected: tested on Linux (Ubuntu 22.04)

Log information

N/A

More information

This was happening on 1.9.1 as well, I upgraded to 1.10.1 in order to see if it was resolved.

Edit: On further research, it looks like leaving the iterator open is the culprit. If you do not go through all the elements produced by componentsAtPoint, the bug occurs. I'm not aware if fully consuming all iterators in Dart is good practice or anything, I would expect the processing to just sort of stop at that position.

misha avatar Nov 07 '23 02:11 misha

Hey @misha can you share a minimal reproducible example for this? Also would you be interested in working on this?

ufrshubham avatar Dec 16 '23 08:12 ufrshubham