Skip to content

Commit

Permalink
Merge pull request ozkriff#669 from ozkriff/fix_end_turn_crash
Browse files Browse the repository at this point in the history
Fix EndTurn-related crash by checking all zscene actions
  • Loading branch information
ozkriff authored Jul 10, 2021
2 parents 577ca3d + de18340 commit 6b9dadc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/screen/battle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl Screen for Battle {
}
self.view.tick(dtime);
self.update_block_timer(dtime)?;
if self.block_timer.is_none() {
if self.block_timer.is_none() && !self.view.any_unfinished_actions() {
if let Some(result) = self.state.battle_result().clone() {
self.send_battle_result(Some(result));
return Ok(StackCommand::Pop);
Expand Down
4 changes: 4 additions & 0 deletions src/screen/battle/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ impl BattleView {
self.scene.add_action(action);
}

pub fn any_unfinished_actions(&self) -> bool {
self.scene.any_unfinished_actions()
}

// TODO: return `(f32, f32)`? width and height separately?
pub fn tile_size(&self) -> f32 {
self.tile_size
Expand Down
2 changes: 2 additions & 0 deletions zscene/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub trait Action: Debug {
fn update(&mut self, _dtime: Duration) {}
fn end(&mut self) {}

/// Note that it return only the main actions' duration and ignores all forks.
/// Also see [Scene::any_unfinished_actions] if you need to check for alive forks.
fn duration(&self) -> Duration {
Duration::new(0, 0)
}
Expand Down
4 changes: 4 additions & 0 deletions zscene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl Scene {
pub fn tick(&mut self, dtime: Duration) {
self.interpreter.tick(dtime);
}

pub fn any_unfinished_actions(&self) -> bool {
!self.interpreter.actions.is_empty()
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 6b9dadc

Please sign in to comment.