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

BoundedPositionBehavior fails with target == null #2655

Closed
markohrastovec opened this issue Aug 18, 2023 · 4 comments · Fixed by #2926
Closed

BoundedPositionBehavior fails with target == null #2655

markohrastovec opened this issue Aug 18, 2023 · 4 comments · Fixed by #2926
Labels

Comments

@markohrastovec
Copy link

Current bug behavior

When I call CameraComponent.setBounds it fails, because BoundedPositionBehavior's _target is null. I traced it down to line 45 in packages/flame/lib/src/camera/behaviors/bounded_position_behavior.dart where _target! is used. In this case it is null, and the exception occurs.

Expected behavior

I would expect setBounds not to fail.

Steps to reproduce

Here is the example that causes a null exception https://zapp.run/edit/flame-zl3i06lvl3j0?entry=lib/main.dart&file=lib/main.dart

Flutter doctor output

I don't believe flutter doctor output is relevant here since there is an example from zapp.run attached.

More environment information

  • Flame version: 1.5.0

Log information

More information

@spydon
Copy link
Member

spydon commented Aug 18, 2023

This doesn't seem to be a problem in 1.8.2, could you try with that version?

@markohrastovec
Copy link
Author

Actually I am working on 1.8.1, but have lowered the minimum working sample to 1.5.0, because I did not know how to make zapp.run working with 1.8.1. I tried it now also with 1.8.2, and the problem stays the same.

@spydon
Copy link
Member

spydon commented Aug 18, 2023

Can you post the stack trace and assertions that you get in 1.8.2? The Zapp example is having some other problems too.

@markohrastovec
Copy link
Author

markohrastovec commented Aug 18, 2023

Here is the stack trace for 1.8.2.

======== Exception caught by scheduler library =====================================================
`The following TypeErrorImpl was thrown during a scheduler callback:
Unexpected null value.

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49      throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 606:63  nullCheck
packages/flame/src/camera/behaviors/bounded_position_behavior.dart 73:38          update
packages/flame/src/camera/behaviors/bounded_position_behavior.dart 39:7           set bounds
packages/flame/src/camera/camera_component.dart 280:22                            setBounds
packages/on_resize_test/main.dart 85:7                                            onGameResize
packages/flame/src/components/core/component.dart 797:14                          <fn>
dart-sdk/lib/core/iterable.dart 346:35                                            forEach
packages/flame/src/components/core/component.dart 795:16                          handleResize
packages/flame/src/components/core/component.dart 405:38                          onGameResize
packages/flame/src/components/core/component.dart 828:5                           [_mount]
packages/flame/src/components/core/component.dart 757:7                           handleLifecycleEventAdd
packages/flame/src/components/core/component_tree_root.dart 83:27                 processLifecycleEvents
packages/flame/src/game/flame_game.dart 121:5                                     updateTree
packages/flame/src/game/flame_game.dart 114:7                                     update
packages/flame/src/game/game_render_box.dart 121:10                               gameLoopCallback
packages/flame/src/game/game_loop.dart 46:13                                      [_tick]
packages/flutter/src/scheduler/ticker.dart 249:12                                 [_tick]
packages/flutter/src/scheduler/binding.dart 1284:15                               [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1136:11                               <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13          forEach
packages/flutter/src/scheduler/binding.dart 1134:16                               handleBeginFrame
packages/flutter/src/scheduler/binding.dart 1051:5                                [_handleBeginFrame]
lib/_engine/engine/platform_dispatcher.dart 1251:13                               invoke1
lib/_engine/engine/platform_dispatcher.dart 223:5                                 invokeOnBeginFrame
lib/_engine/engine/initialization.dart 181:45                                     <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39  dcall`

`This exception was thrown in the context of a scheduler callback. When the scheduler callback was _registered_ (as opposed to when the exception was thrown), this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 942:28                get current
packages/flutter/src/scheduler/binding.dart 122:33                                <fn>
packages/flutter/src/scheduler/binding.dart 124:14                                new
packages/flutter/src/scheduler/binding.dart 568:49                                scheduleFrameCallback
packages/flutter/src/scheduler/ticker.dart 265:46                                 scheduleTick
packages/flutter/src/scheduler/ticker.dart 171:7                                  start
packages/flame/src/game/game_loop.dart 54:15                                      start
packages/flame/src/game/game_render_box.dart 97:15                                [_attachGame]
packages/flame/src/game/game_render_box.dart 88:5                                 attach
packages/flutter/src/foundation/node.dart 137:12                                  adoptChild
packages/flutter/src/rendering/object.dart 1703:11                                adoptChild
packages/flutter/src/rendering/object.dart 3863:7                                 set child
packages/flutter/src/widgets/framework.dart 6450:17                               insertRenderObjectChild
packages/flutter/src/widgets/framework.dart 6268:35                               attachRenderObject
packages/flutter/src/widgets/framework.dart 5943:5                                mount
packages/flutter/src/widgets/framework.dart 3971:15                               inflateWidget
packages/flutter/src/widgets/framework.dart 3708:18                               updateChild
packages/flutter/src/widgets/framework.dart 6435:14                               mount
packages/flutter/src/widgets/framework.dart 3971:15                               inflateWidget
packages/flutter/src/widgets/framework.dart 3708:18                               updateChild
packages/flutter/src/widgets/framework.dart 6435:14                               mount
packages/flutter/src/widgets/framework.dart 3971:15                               inflateWidget
packages/flutter/src/widgets/framework.dart 3708:18                               updateChild
packages/flutter/src/widgets/framework.dart 5111:16                               performRebuild
packages/flutter/src/widgets/framework.dart 5251:11                               performRebuild
packages/flutter/src/widgets/framework.dart 4805:7                                rebuild
packages/flutter/src/widgets/framework.dart 5068:5                                [_firstBuild]
packages/flutter/src/widgets/framework.dart 5242:11                               [_firstBuild]
packages/flutter/src/widgets/framework.dart 5062:5                                mount
packages/flutter/src/widgets/framework.dart 3971:15                               inflateWidget
packages/flutter/src/widgets/framework.dart 6570:36                               inflateWidget
packages/flutter/src/widgets/framework.dart 3708:18                               updateChild
packages/flutter/src/widgets/framework.dart 6153:32                               updateChildren
packages/flutter/src/widgets/framework.dart 6595:17                               update
packages/flutter/src/widgets/framework.dart 3686:14                               updateChild
packages/flutter/src/widgets/framework.dart 5111:16                               performRebuild
packages/flutter/src/widgets/framework.dart 5251:11                               performRebuild
packages/flutter/src/widgets/framework.dart 4805:7                                rebuild
packages/flutter/src/widgets/framework.dart 5274:5                                update
packages/flutter/src/widgets/framework.dart 3686:14                               updateChild
packages/flutter/src/widgets/layout_builder.dart 135:18                           layoutCallback
packages/flutter/src/widgets/framework.dart 2720:19                               buildScope
packages/flutter/src/widgets/layout_builder.dart 153:5                            [_layout]
packages/flutter/src/rendering/object.dart 2506:59                                <fn>
packages/flutter/src/rendering/object.dart 1062:15                                [_enableMutationsToDirtySubtrees]
packages/flutter/src/rendering/object.dart 2506:7                                 invokeLayoutCallback
packages/flutter/src/widgets/layout_builder.dart 228:7                            rebuildIfNecessary
packages/flutter/src/widgets/layout_builder.dart 313:5                            performLayout
packages/flutter/src/rendering/object.dart 2234:7                                 [_layoutWithoutResize]
packages/flutter/src/rendering/object.dart 1016:17                                flushLayout
packages/flutter/src/rendering/binding.dart 492:19                                drawFrame
packages/flutter/src/widgets/binding.dart 905:13                                  drawFrame
packages/flutter/src/rendering/binding.dart 358:5                                 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1284:15                               [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1214:9                                handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1072:5                                [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1236:13                               invoke
lib/_engine/engine/platform_dispatcher.dart 244:5                                 invokeOnDrawFrame
lib/_engine/engine/initialization.dart 190:45                                     <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39  dcall
====================================================================================================`

spydon pushed a commit that referenced this issue Dec 17, 2023
…is null (#2926)

The `bounds` setter of `BoundedPositionBehavior` tries to update the
target's position when bounds are updated. But it wasn't checking if the
target is null. This was causing null exceptions while updating bounds
of an unmounted `BoundedPositionBehavior` with null target (as seen in
[this failing test
case](https://github.com/flame-engine/flame/actions/runs/7231182930/job/19704091006#step:5:1291)).
This PR fixes that by checking if the target is null before updating the
position.


Closes #2655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants