From 27d6b2645e46ff0050db9324d40a95d54950bd4c Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 4 Sep 2014 12:15:54 -0700 Subject: [PATCH] meta-backend: Fix the max device calculation on removal If we add device 2, then add device 254, then remove device 254, then the max device ID will be 253. Scan through all the devices again on removal to calculate a new max device ID. --- src/backends/meta-backend.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index efcca94ec..1b179cdab 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -119,8 +119,16 @@ destroy_device_monitor (MetaBackend *backend, int device_id) { g_clear_object (&backend->device_monitors[device_id]); + if (device_id == backend->device_id_max) - backend->device_id_max--; + { + /* Reset the max device ID */ + int i, new_max = 0; + for (i = 0; i < backend->device_id_max; i++) + if (backend->device_monitors[i] != NULL) + new_max = i; + backend->device_id_max = new_max; + } } static void