Skip to content

Commit

Permalink
Less flaky device handling (#3602)
Browse files Browse the repository at this point in the history
Fix some dubious assumption in DefaultInputDeviceHub.

Fixes: #3601
  • Loading branch information
Saviq authored Sep 19, 2024
2 parents 5f1ce00 + 08c5784 commit 65d9221
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server/input/default_input_device_hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ void mi::ExternalInputDeviceHub::Internal::changes_complete()
observer->changes_complete();
});

auto end_it = handles.end();
for (auto const& dev : removed)
end_it = remove(begin(handles), end(handles), dev);
if (end_it != handles.end())
handles.erase(end_it, end(handles));
{
handles.erase(remove(begin(handles), end(handles), dev), end(handles));
}

for (auto const& dev : added)
{
if (auto handle = std::dynamic_pointer_cast<DefaultDevice>(dev))
Expand Down Expand Up @@ -757,6 +757,13 @@ void mi::DefaultInputDeviceHub::device_changed(Device* dev)
{
std::unique_lock lock{mutex};
auto dev_it = find_if(begin(handles), end(handles), [dev](auto const& ptr){return ptr.get() == dev;});

if (dev_it == end(handles))
{
log_debug("Ignoring changes to unknown device (it was likely removed already");
return;
}

std::shared_ptr<Device> const dev_shared = *dev_it;
if (pending_changes)
{
Expand Down

0 comments on commit 65d9221

Please sign in to comment.