Skip to content
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: CameraComponent no longer throws Concurrent modification on stop #2997

Conversation

lohnn
Copy link
Contributor

@lohnn lohnn commented Jan 23, 2024

Description

When camera is following a component and trying to follow another target I got an exception:

dart:core                                              Iterable.forEach
package:flame/src/camera/camera_component.dart 326:25  CameraComponent.stop
package:flame/src/camera/camera_component.dart 309:5   CameraComponent.follow
test/camera/camera_component_test.dart 69:14           main.<fn>.<fn>
package:flame_test/src/test_flame_game.dart 80:21      testWithGame.<fn>

Concurrent modification during iteration: _Set len:0.

Copying viewfinder children before iterating through it and removing child from parent does the trick, as we are not iterating through the same list as we are removing items from, but rather a copy of it.

I tried to use camera from game provided in the test but it is AFAIK not mounted and will hence not queue modifications (adds and removes). Hence I create a new camera and mount it.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Replace or remove this text.

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, just a minor comment on the test

packages/flame/test/camera/camera_component_test.dart Outdated Show resolved Hide resolved
@spydon spydon enabled auto-merge (squash) January 23, 2024 08:49
@spydon spydon merged commit 6a1059b into flame-engine:main Jan 23, 2024
8 checks passed
@lohnn lohnn deleted the fix/camera-component-stop-concurrent-modification branch January 23, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants