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

Add guard to prevent onDestroy being called after component has been removed #528

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
21 changes: 8 additions & 13 deletions lib/objects/flying_attack_game_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ class FlyingAttackGameObject extends AnimatedGameObject
}

void _destroyObject(GameComponent component) {
if (isRemoving) return;
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
Loading