Skip to content

Commit

Permalink
fix: panic on web
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Jan 31, 2024
1 parent 6f4fdc7 commit 794fedc
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/animation_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,24 +431,26 @@ pub mod systems {
continue;
};
info!("animation controller transitioning to={next_state}");

controller.started = false;
controller.playing = false;

let target_state = controller
.states
.get(&next_state)
.unwrap_or_else(|| panic!("state not found: '{}'", next_state));
let target_handle = target_state.asset.clone().unwrap_or(cur_handle.clone());

// Transitions to new assets will always reset the playhead
let mut changed_assets = false;
if let Some(ref next_asset) = target_state.asset {
if cur_handle.id() != next_asset.id() {
*cur_handle = next_asset.clone();
changed_assets = true;
}
}
let Some(asset) = assets.get_mut(target_handle.id()) else {
warn!("Asset not ready for transition... re-queue'ing...");
controller.next_state.replace(next_state);
return;
};

// Switch to asset
let changed_assets = cur_handle.id() != target_handle.id();
*cur_handle = target_handle.clone();

let asset = assets.get_mut(cur_handle.id()).unwrap();
let playback_settings = playback_settings.cloned().unwrap_or_default();
let playhead = asset.calculate_playhead(&playback_settings).unwrap();
// Reset play state
Expand Down

0 comments on commit 794fedc

Please sign in to comment.