[gimp] Issue #2210 - GIMP crashes on startup if usb mouse is present



commit 7adb6c26e5913b70decfcd7119354a4f59feb216
Author: Michael Natterer <mitch gimp org>
Date:   Fri Oct 12 19:55:56 2018 +0200

    Issue #2210 - GIMP crashes on startup if usb mouse is present
    
    In GimpDeviceInfo, make sure that the info->axes and info->keys arrays
    always have info->n_axes and info->n_keys members. Also sync axes and
    keys between GdkDevice and GimpDeviceInfo more often, and some
    cleanup.

 app/widgets/gimpdeviceinfo.c | 74 +++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 39 deletions(-)
---
diff --git a/app/widgets/gimpdeviceinfo.c b/app/widgets/gimpdeviceinfo.c
index ff62faece3..19a1abe502 100644
--- a/app/widgets/gimpdeviceinfo.c
+++ b/app/widgets/gimpdeviceinfo.c
@@ -227,15 +227,27 @@ gimp_device_info_constructed (GObject *object)
 
   if (info->device)
     {
+      gint i;
+
       g_object_set_data (G_OBJECT (info->device), GIMP_DEVICE_INFO_DATA_KEY,
                          info);
 
       gimp_object_set_name (GIMP_OBJECT (info),
                             gdk_device_get_name (info->device));
 
-      info->mode    = gdk_device_get_mode (info->device);
-      info->n_axes  = gdk_device_get_n_axes (info->device);
-      info->n_keys  = gdk_device_get_n_keys (info->device);
+      info->mode = gdk_device_get_mode (info->device);
+
+      info->n_axes = gdk_device_get_n_axes (info->device);
+      info->axes = g_new0 (GdkAxisUse, info->n_axes);
+      for (i = 0; i < info->n_axes; i++)
+        info->axes[i] = gdk_device_get_axis_use (info->device, i);
+
+      info->n_keys = gdk_device_get_n_keys (info->device);
+      info->keys = g_new0 (GimpDeviceKey, info->n_keys);
+      for (i = 0; i < info->n_keys; i++)
+        gdk_device_get_key (info->device, i,
+                            &info->keys[i].keyval,
+                            &info->keys[i].modifiers);
     }
 }
 
@@ -292,21 +304,15 @@ gimp_device_info_set_property (GObject      *object,
         if (array)
           {
             gint i;
-            gint n_device_values;
+            gint n_device_values = gimp_value_array_length (array);
 
             if (device)
-              {
-                n_device_values = MIN (gimp_value_array_length (array),
-                                       gdk_device_get_n_axes (device));
-              }
-            else
-              {
-                n_device_values = gimp_value_array_length (array);
+              n_device_values = MIN (n_device_values,
+                                     gdk_device_get_n_axes (device));
 
-                info->n_axes = n_device_values;
-                info->axes   = g_renew (GdkAxisUse, info->axes, info->n_axes);
-                memset (info->axes, 0, info->n_axes * sizeof (GdkAxisUse));
-              }
+            info->n_axes = n_device_values;
+            info->axes   = g_renew (GdkAxisUse, info->axes, info->n_axes);
+            memset (info->axes, 0, info->n_axes * sizeof (GdkAxisUse));
 
             for (i = 0; i < n_device_values; i++)
               {
@@ -327,21 +333,15 @@ gimp_device_info_set_property (GObject      *object,
         if (array)
           {
             gint i;
-            gint n_device_values;
+            gint n_device_values = gimp_value_array_length (array);
 
             if (device)
-              {
-                n_device_values = MIN (gimp_value_array_length (array),
-                                       gdk_device_get_n_keys (device));
-              }
-            else
-              {
-                n_device_values = gimp_value_array_length (array);
+              n_device_values = MIN (n_device_values,
+                                     gdk_device_get_n_keys (device));
 
-                info->n_keys = n_device_values;
-                info->keys   = g_renew (GimpDeviceKey, info->keys, info->n_keys);
-                memset (info->keys, 0, info->n_keys * sizeof (GimpDeviceKey));
-              }
+            info->n_keys = n_device_values;
+            info->keys   = g_renew (GimpDeviceKey, info->keys, info->n_keys);
+            memset (info->keys, 0, info->n_keys * sizeof (GimpDeviceKey));
 
             for (i = 0; i < n_device_values; i++)
               {
@@ -693,7 +693,7 @@ gimp_device_info_set_device (GimpDeviceInfo *info,
       info->axes   = g_renew (GdkAxisUse, info->axes, info->n_axes);
       memset (info->axes, 0, info->n_axes * sizeof (GdkAxisUse));
 
-      for (i = 0; i < gdk_device_get_n_axes (device); i++)
+      for (i = 0; i < info->n_axes; i++)
         gimp_device_info_set_axis_use (info, i,
                                        gdk_device_get_axis_use (device, i));
 
@@ -701,7 +701,7 @@ gimp_device_info_set_device (GimpDeviceInfo *info,
       info->keys   = g_renew (GimpDeviceKey, info->keys, info->n_keys);
       memset (info->keys, 0, info->n_keys * sizeof (GimpDeviceKey));
 
-      for (i = 0; i < MIN (info->n_keys, gdk_device_get_n_keys (device)); i++)
+      for (i = 0; i < info->n_keys; i++)
         {
           guint           keyval    = 0;
           GdkModifierType modifiers = 0;
@@ -1041,8 +1041,8 @@ gimp_device_info_set_axis_use (GimpDeviceInfo *info,
     {
       if (info->device)
         gdk_device_set_axis_use (info->device, axis, use);
-      else
-        info->axes[axis] = use;
+
+      info->axes[axis] = use;
 
       g_object_notify (G_OBJECT (info), "axes");
     }
@@ -1104,14 +1104,10 @@ gimp_device_info_set_key (GimpDeviceInfo *info,
       modifiers != old_modifiers)
     {
       if (info->device)
-        {
-          gdk_device_set_key (info->device, key, keyval, modifiers);
-        }
-      else
-        {
-          info->keys[key].keyval    = keyval;
-          info->keys[key].modifiers = modifiers;
-        }
+        gdk_device_set_key (info->device, key, keyval, modifiers);
+
+      info->keys[key].keyval    = keyval;
+      info->keys[key].modifiers = modifiers;
 
       g_object_notify (G_OBJECT (info), "keys");
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]