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

Fix out-of-bounds selection bug #8

Merged
merged 1 commit into from
Feb 24, 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
9 changes: 8 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ impl App {
items.push(bpf_program);
}

let state = state.lock().unwrap();
let mut state = state.lock().unwrap();
let mut data_buf = data_buf.lock().unwrap();
if let Some(index) = state.selected() {
// If the selected index is out of bounds, unselect it.
// This can happen if a program exits while it's selected.
if index >= items.len() {
state.select(None);
continue;
}

let bpf_program = &items[index];
data_buf.push_back(PeriodMeasure {
cpu_time_percent: bpf_program.cpu_time_percent(),
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ fn run_draw_loop<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> Result
fn ui(f: &mut Frame, app: &mut App) {
let rects = Layout::vertical([Constraint::Min(5), Constraint::Length(3)]).split(f.size());

// This can happen when the program exists while the user is viewing the graphs.
// In this case, we want to switch back to the table view.
if app.selected_program().is_none() && app.show_graphs {
app.show_graphs = false;
}

if app.show_graphs {
render_graphs(f, app, rects[0]);
} else {
Expand Down