Skip to content

Commit

Permalink
Prevent render thread panic when the graph is not fully initialized yet
Browse files Browse the repository at this point in the history
When the rendering has already commenced but the control thread has not
set up the destination node, a panic occurs:

```
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/render/graph.rs:479:14
```

We now wait with rendering before the node count is at least 1
  • Loading branch information
orottier committed Jul 19, 2023
1 parent a750aa3 commit 068352c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/render/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ impl Graph {
}
}

/// Check if the graph is fully initialized and can start rendering
pub fn is_active(&self) -> bool {
// currently we only require the destination node to be present
!self.nodes.is_empty()
}

pub fn add_node(
&mut self,
index: AudioNodeId,
Expand Down
2 changes: 1 addition & 1 deletion src/render/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl RenderThread {
self.handle_control_messages();

// if the thread is still booting, or shutting down, fill with silence
if self.graph.is_none() {
if !self.graph.as_ref().is_some_and(Graph::is_active) {
output_buffer.fill(S::from_sample_(0.));
return;
}
Expand Down

0 comments on commit 068352c

Please sign in to comment.