Skip to content

Commit

Permalink
High-level API: Avoid possible crash in FxChain methods when track no…
Browse files Browse the repository at this point in the history
…t available anymore

helgoboss/helgobox#1273
  • Loading branch information
helgoboss committed Oct 19, 2024
1 parent cfa5816 commit 4801186
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions main/high/src/fx_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ impl FxChain {
let reaper = Reaper::get().medium_reaper();
match &self.context {
FxChainContext::Track { track, is_input_fx } => {
if track.load_and_check_if_necessary_or_err().is_err() {
return 0;
}
if *is_input_fx {
unsafe { reaper.track_fx_get_rec_count(track.raw()) }
} else {
Expand All @@ -82,6 +85,9 @@ impl FxChain {
let reaper = Reaper::get().medium_reaper();
match &self.context {
FxChainContext::Track { track, is_input_fx } => {
if track.load_and_check_if_necessary_or_err().is_err() {
return FxChainVisibility::Hidden;
}
if *is_input_fx {
unsafe { reaper.track_fx_get_rec_chain_visible(track.raw()) }
} else {
Expand Down Expand Up @@ -112,7 +118,9 @@ impl FxChain {
FxChainContext::Take(_) => todo!(),
_ => {
let track = self.track_or_master_track();

if track.load_and_check_if_necessary_or_err().is_err() {
return;
}
let instruction = if visible {
let location = get_track_fx_location(0, self.is_input_fx());
FxShowInstruction::ShowChain(location)
Expand Down Expand Up @@ -142,6 +150,7 @@ impl FxChain {
FxChainContext::Take(_) => todo!(),
_ => {
let (track, location) = fx.track_and_location();
track.load_and_check_if_necessary_or_err()?;
unsafe {
reaper.track_fx_copy_to_track(
(track.raw(), location),
Expand Down Expand Up @@ -357,6 +366,7 @@ DOCKED 0
if *is_input_fx {
return None;
}
track.load_and_check_if_necessary_or_err().ok()?;
let fx_index = unsafe {
Reaper::get()
.medium_reaper()
Expand Down Expand Up @@ -396,10 +406,12 @@ DOCKED 0
let fx_index = match self.context() {
FxChainContext::Take(_) => todo!(),
_ => unsafe {
let track = self.track_or_master_track();
track.load_and_check_if_necessary_or_err().ok()?;
Reaper::get()
.medium_reaper()
.track_fx_add_by_name_add(
self.track_or_master_track().raw(),
track.raw(),
name,
if self.is_input_fx() {
TrackFxChainType::InputFxChain
Expand Down Expand Up @@ -458,6 +470,7 @@ DOCKED 0
let fx_index = match self.context() {
FxChainContext::Take(_) => todo!(),
FxChainContext::Track { track, .. } => unsafe {
track.load_and_check_if_necessary_or_err().ok()?;
Reaper::get().medium_reaper().track_fx_add_by_name_query(
track.raw(),
name,
Expand Down
2 changes: 1 addition & 1 deletion main/high/src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ impl Track {
self.complain_if_not_valid();
}

fn load_and_check_if_necessary_or_err(&self) -> Result<(), &'static str> {
pub(crate) fn load_and_check_if_necessary_or_err(&self) -> Result<(), &'static str> {
self.load_if_necessary_or_err()?;
self.err_if_not_valid()?;
Ok(())
Expand Down

0 comments on commit 4801186

Please sign in to comment.