[libchamplain] Catch the division by 0 as soon as possible



commit 1103bfef94aca4772745f9187d00af587d80fdf2
Author: Emmanuel Rodriguez <emmanuel rodriguez booking com>
Date:   Fri Jul 31 20:53:34 2009 +0200

    Catch the division by 0 as soon as possible

 tidy/tidy-finger-scroll.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/tidy/tidy-finger-scroll.c b/tidy/tidy-finger-scroll.c
index f57f379..55ebe85 100644
--- a/tidy/tidy-finger-scroll.c
+++ b/tidy/tidy-finger-scroll.c
@@ -424,22 +424,23 @@ button_release_event_cb (ClutterActor *actor,
             time_diff = release_time.tv_usec +
                         (G_USEC_PER_SEC - motion_time.tv_usec);
           
-          /* Work out the fraction of 1/60th of a second that has elapsed */
-          frac = clutter_qdivx (CLUTTER_FLOAT_TO_FIXED (time_diff/1000.0),
-                                CLUTTER_FLOAT_TO_FIXED (1000.0/60.0));
-          
-          /* On a macbook that's running Ubuntu 9.04 sometimes frac is 0 and
-             this causes a division by 0. Here we try to avoid that.
+          /* On a macbook that's running Ubuntu 9.04 sometimes 'time_diff' is 0
+             and this causes a division by 0 when computing 'frac'. This check
+             avoids this error.
            */
-          if (frac == 0)
+          if (time_diff == 0)
             {
-                g_print ("Caught a division by 0 (%d / %d).\n",
+                g_print ("Preventing a division by 0 (%d / %d).\n",
                     CLUTTER_FLOAT_TO_FIXED (time_diff/1000.0),
                     CLUTTER_FLOAT_TO_FIXED (1000.0/60.0)
                 );
                 clutter_event_put ((ClutterEvent *)event);
                 return TRUE;
             }
+
+          /* Work out the fraction of 1/60th of a second that has elapsed */
+          frac = clutter_qdivx (CLUTTER_FLOAT_TO_FIXED (time_diff/1000.0),
+                                CLUTTER_FLOAT_TO_FIXED (1000.0/60.0));
           /* See how many units to move in 1/60th of a second */
           priv->dx = CLUTTER_UNITS_FROM_FIXED(clutter_qdivx (
                      CLUTTER_UNITS_TO_FIXED(x_origin - x), frac));



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