From 1cfe12b9c0cac1cec73058ca0267bc74bb073db1 Mon Sep 17 00:00:00 2001 From: tkshnwesper Date: Tue, 11 Jun 2024 15:48:37 +0530 Subject: [PATCH 1/3] fix bug where onDestroy was being even after being removed --- lib/objects/flying_attack_game_object.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/objects/flying_attack_game_object.dart b/lib/objects/flying_attack_game_object.dart index a276b5653..5eb22097f 100644 --- a/lib/objects/flying_attack_game_object.dart +++ b/lib/objects/flying_attack_game_object.dart @@ -132,7 +132,7 @@ class FlyingAttackGameObject extends AnimatedGameObject } void _destroyObject(GameComponent component) { - if (isRemoving) return; + if (isRemoving || isRemoved) return; removeFromParent(); if (animationDestroy != null) { if (direction != null) { From d8bca638453d82490b464dd477be544916d2b319 Mon Sep 17 00:00:00 2001 From: tkshnwesper Date: Tue, 11 Jun 2024 15:55:14 +0530 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df83ff855..e51be0c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 3.9.5 - - Fix Joystick bug when viewport is fixed resolution. [#526](https://github.com/RafaelBarbosatec/bonfire/issues/526) +- Add guard in `FlyingAttackGameObject` to prevent calling `onDestroy` after component has been destroyed. # 3.9.4 - Fix bug in `FollowerWidget`. From f8f508556307b80a4e5cf79829ac4ea3dd2b6192 Mon Sep 17 00:00:00 2001 From: tkshnwesper Date: Tue, 11 Jun 2024 16:02:09 +0530 Subject: [PATCH 3/3] remove redundant parameter --- lib/objects/flying_attack_game_object.dart | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/objects/flying_attack_game_object.dart b/lib/objects/flying_attack_game_object.dart index 5eb22097f..3f2ce6cee 100644 --- a/lib/objects/flying_attack_game_object.dart +++ b/lib/objects/flying_attack_game_object.dart @@ -135,10 +135,11 @@ class FlyingAttackGameObject extends AnimatedGameObject if (isRemoving || isRemoved) return; removeFromParent(); if (animationDestroy != null) { - if (direction != null) { - _destroyByDirection(direction!, dtUpdate, component); + final currentDirection = direction; + if (currentDirection != null) { + _destroyByDirection(currentDirection); } else { - _destroyByAngle(component); + _destroyByAngle(); } } removeAll(children); @@ -149,11 +150,7 @@ class FlyingAttackGameObject extends AnimatedGameObject return gameRef.map.toRect().contains(center.toOffset()); } - void _destroyByDirection( - Direction direction, - double dt, - GameComponent component, - ) { + void _destroyByDirection(Direction direction) { Vector2 positionDestroy; double biggerSide = max(width, height); @@ -236,12 +233,11 @@ class FlyingAttackGameObject extends AnimatedGameObject innerSize.x, innerSize.y, ), - component, ); } } - void _destroyByAngle(GameComponent component) { + void _destroyByAngle() { double nextX = (width / 2) * _cosAngle; double nextY = (height / 2) * _senAngle; @@ -277,12 +273,11 @@ class FlyingAttackGameObject extends AnimatedGameObject innerSize.x, innerSize.y, ), - component, ); } } - void _applyDestroyDamage(Rect rectPosition, GameComponent component) { + void _applyDestroyDamage(Rect rectPosition) { gameRef.add( DamageHitbox( id: id,