Fixed bug 2503 - Loop indexing and event union errors in SDL_gesture.c
authorSam Lantinga <slouken@libsdl.org>
Thu, 17 Apr 2014 19:52:15 -0700
changeset 8705fee2f7e242a1
parent 8704 2732c28ca4db
child 8706 0c9660fdf9bf
Fixed bug 2503 - Loop indexing and event union errors in SDL_gesture.c

Lasse Öörni

While enabling $1 gesture support in the Urho3D engine which uses SDL2 I detected some errors in the gesture code in SDL_gesture.c:

- In the function SDL_SaveAllDollarTemplates() the following line should use index variable j instead of i:

rtrn += SaveTemplate(&touch->dollarTemplate[i], dst);

- In the function SDL_SaveDollarTemplate() the following code should use index variable j instead of i:

if (touch->dollarTemplate[i].hash == gestureId) {
return SaveTemplate(&touch->dollarTemplate[i], dst);

- In the function SDL_SendGestureDollar() the x & y coordinates are being written to the mgesture structure, which results in garbage due to dgesture and mgesture being different data structures inside the union. The coordinates should be written to dgesture.x & dgesture.y respectively
src/events/SDL_gesture.c
     1.1 --- a/src/events/SDL_gesture.c	Thu Apr 17 17:24:27 2014 -0700
     1.2 +++ b/src/events/SDL_gesture.c	Thu Apr 17 19:52:15 2014 -0700
     1.3 @@ -137,7 +137,7 @@
     1.4      for (i = 0; i < SDL_numGestureTouches; i++) {
     1.5          SDL_GestureTouch* touch = &SDL_gestureTouch[i];
     1.6          for (j = 0; j < touch->numDollarTemplates; j++) {
     1.7 -            rtrn += SaveTemplate(&touch->dollarTemplate[i], dst);
     1.8 +            rtrn += SaveTemplate(&touch->dollarTemplate[j], dst);
     1.9          }
    1.10      }
    1.11      return rtrn;
    1.12 @@ -150,7 +150,7 @@
    1.13          SDL_GestureTouch* touch = &SDL_gestureTouch[i];
    1.14          for (j = 0; j < touch->numDollarTemplates; j++) {
    1.15              if (touch->dollarTemplate[i].hash == gestureId) {
    1.16 -                return SaveTemplate(&touch->dollarTemplate[i], dst);
    1.17 +                return SaveTemplate(&touch->dollarTemplate[j], dst);
    1.18              }
    1.19          }
    1.20      }
    1.21 @@ -454,8 +454,8 @@
    1.22      SDL_Event event;
    1.23      event.dgesture.type = SDL_DOLLARGESTURE;
    1.24      event.dgesture.touchId = touch->id;
    1.25 -    event.mgesture.x = touch->centroid.x;
    1.26 -    event.mgesture.y = touch->centroid.y;
    1.27 +    event.dgesture.x = touch->centroid.x;
    1.28 +    event.dgesture.y = touch->centroid.y;
    1.29      event.dgesture.gestureId = gestureId;
    1.30      event.dgesture.error = error;
    1.31      /* A finger came up to trigger this event. */