Skip to content

Fix CPU/GPU usage in file dialog and crash with single-commit repos#75

Open
marcoxyz123 wants to merge 2 commits intogit-bahn:masterfrom
marcoxyz123:fix/event-loop-and-single-commit-crash
Open

Fix CPU/GPU usage in file dialog and crash with single-commit repos#75
marcoxyz123 wants to merge 2 commits intogit-bahn:masterfrom
marcoxyz123:fix/event-loop-and-single-commit-crash

Conversation

@marcoxyz123
Copy link

Summary

This PR fixes two bugs:

Bug 1: 100% CPU/GPU usage in file dialog view

  • Cause: Event loop ignored Event::Update when showing the file dialog, causing next_repo_refresh to never update after expiration. This resulted in poll() returning immediately with zero timeout, creating a busy loop.
  • Fix: Changed if let Event::Input to match statements that handle both Event::Input and Event::Update, updating the refresh timer in both branches.

Bug 2: Crash with single-commit repositories

  • Cause: Multiple places used len() - 1 which causes unsigned integer underflow when length is 0 (wraps to usize::MAX). This caused invalid comparisons and out-of-bounds index access.
  • Fix:
    • Added guard for empty indices in graph_view render function
    • Changed len() - 1 to len().saturating_sub(1) throughout
    • Used safe .get(idx).copied() instead of direct indexing
    • Pre-computed max index values to avoid repeated calculations

Testing

  • cargo fmt --all -- --check passes
  • cargo clippy --all --all-targets -- --deny warnings passes
  • cargo test --all passes
  • Release build succeeds

The event loop ignored Event::Update when showing the file dialog,
causing next_repo_refresh to never be updated after expiration.
This resulted in poll() returning immediately with zero timeout,
creating a busy loop.

Changed if-let to match statements that handle both Event::Input
and Event::Update, updating the refresh timer in both branches.
Multiple places used len() - 1 which causes unsigned integer underflow
when length is 0, wrapping to usize::MAX. This caused invalid comparisons
in bounds checks and subsequent out-of-bounds index access.

Changes:
- Added guard for empty indices in graph_view render function
- Changed len() - 1 to len().saturating_sub(1) throughout
- Used safe .get(idx).copied() instead of direct indexing
- Pre-computed max index values to avoid repeated calculations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant