Skip to content

Conversation

@Dolphindalt
Copy link
Contributor

@Dolphindalt Dolphindalt commented Nov 22, 2025

Description of the change

When you unpair the last device and then try to cycle to the next device, here's what happens:

  1. Unpairing removes the device from the Bluetooth adapter
  2. The refresh() method updates the paired_devices vector with the new (shorter) list
  3. The paired_devices_state selection index was never updated, so it could still point to an out-of-bounds index
  4. When you perform an action on the devices, the code tries to access controller.paired_devices[index] where index is out of bounds results in a panic

I added bounds checking in the refresh() method that:

  • Detects when the paired devices list shrinks
  • Checks if the currently selected index is now out of bounds
  • Adjusts the selection to either the last valid device or None if no devices remain

This is the same pattern already used for handling removed adapters but now applied to paired devices as well.

@pythops
Copy link
Owner

pythops commented Nov 22, 2025

First, thanks for the PR.
Second, even though I think this might solve the issue, I am not happy with my first implementation overall. There is a better way to use AdapterEvent to handle the update on the devices.
We still can merge your PR ofc, then I will be working on a big refactor

@pythops pythops merged commit aca9b2e into pythops:master Nov 22, 2025
1 check passed
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.

2 participants