瀏覽代碼

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
Sam Lantinga 12 年之前
父節點
當前提交
f4b77110d2
共有 1 個文件被更改,包括 4 次插入 和 4 次删除
  1. 4 4
      src/events/SDL_gesture.c

+ 4 - 4
src/events/SDL_gesture.c

@@ -137,7 +137,7 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *dst)
     for (i = 0; i < SDL_numGestureTouches; i++) {
     for (i = 0; i < SDL_numGestureTouches; i++) {
         SDL_GestureTouch* touch = &SDL_gestureTouch[i];
         SDL_GestureTouch* touch = &SDL_gestureTouch[i];
         for (j = 0; j < touch->numDollarTemplates; j++) {
         for (j = 0; j < touch->numDollarTemplates; j++) {
-            rtrn += SaveTemplate(&touch->dollarTemplate[i], dst);
+            rtrn += SaveTemplate(&touch->dollarTemplate[j], dst);
         }
         }
     }
     }
     return rtrn;
     return rtrn;
@@ -150,7 +150,7 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
         SDL_GestureTouch* touch = &SDL_gestureTouch[i];
         SDL_GestureTouch* touch = &SDL_gestureTouch[i];
         for (j = 0; j < touch->numDollarTemplates; j++) {
         for (j = 0; j < touch->numDollarTemplates; j++) {
             if (touch->dollarTemplate[i].hash == gestureId) {
             if (touch->dollarTemplate[i].hash == gestureId) {
-                return SaveTemplate(&touch->dollarTemplate[i], dst);
+                return SaveTemplate(&touch->dollarTemplate[j], dst);
             }
             }
         }
         }
     }
     }
@@ -454,8 +454,8 @@ static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
     SDL_Event event;
     SDL_Event event;
     event.dgesture.type = SDL_DOLLARGESTURE;
     event.dgesture.type = SDL_DOLLARGESTURE;
     event.dgesture.touchId = touch->id;
     event.dgesture.touchId = touch->id;
-    event.mgesture.x = touch->centroid.x;
-    event.mgesture.y = touch->centroid.y;
+    event.dgesture.x = touch->centroid.x;
+    event.dgesture.y = touch->centroid.y;
     event.dgesture.gestureId = gestureId;
     event.dgesture.gestureId = gestureId;
     event.dgesture.error = error;
     event.dgesture.error = error;
     /* A finger came up to trigger this event. */
     /* A finger came up to trigger this event. */