Fixed bug 2054 - SDL_GetError: "Unknown touch device"
authorSam Lantinga <slouken@libsdl.org>
Thu, 28 May 2015 12:55:01 -0700
changeset 96797fc4a8be47a8
parent 9678 9e8323b058d6
child 9680 1d13a878b066
Fixed bug 2054 - SDL_GetError: "Unknown touch device"

Volumetric

The "Unknown touch device" message appears because the initial touch device setup loop uses SDL_GetTouch() as a guard for calling SDL_AddTouch(). SDL_GetTouch() will always report "Unknown touch device" since the device hasn't been added yet. The SDL_GetTouch() call is unnecessary since SDL_AddTouch() calls SDL_GetTouchIndex() to verify that the device hasn't been added yet, and SDL_GetTouchIndex() has the benefit of not reporting an error for a device it can't find.
src/video/cocoa/SDL_cocoawindow.m
src/video/emscripten/SDL_emscriptenevents.c
src/video/wayland/SDL_waylandtouch.c
src/video/windows/SDL_windowsevents.c
src/video/x11/SDL_x11xinput2.c
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu May 28 12:48:20 2015 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu May 28 12:55:01 2015 -0700
     1.3 @@ -951,10 +951,8 @@
     1.4  
     1.5      for (NSTouch *touch in touches) {
     1.6          const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
     1.7 -        if (!SDL_GetTouch(touchId)) {
     1.8 -            if (SDL_AddTouch(touchId, "") < 0) {
     1.9 -                return;
    1.10 -            }
    1.11 +        if (SDL_AddTouch(touchId, "") < 0) {
    1.12 +            return;
    1.13          }
    1.14  
    1.15          const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
     2.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Thu May 28 12:48:20 2015 -0700
     2.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Thu May 28 12:55:01 2015 -0700
     2.3 @@ -376,10 +376,8 @@
     2.4      int i;
     2.5  
     2.6      SDL_TouchID deviceId = 0;
     2.7 -    if (!SDL_GetTouch(deviceId)) {
     2.8 -        if (SDL_AddTouch(deviceId, "") < 0) {
     2.9 -             return 0;
    2.10 -        }
    2.11 +    if (SDL_AddTouch(deviceId, "") < 0) {
    2.12 +         return 0;
    2.13      }
    2.14  
    2.15      for (i = 0; i < touchEvent->numTouches; i++) {
     3.1 --- a/src/video/wayland/SDL_waylandtouch.c	Thu May 28 12:48:20 2015 -0700
     3.2 +++ b/src/video/wayland/SDL_waylandtouch.c	Thu May 28 12:55:01 2015 -0700
     3.3 @@ -89,11 +89,9 @@
     3.4      */
     3.5  
     3.6      SDL_TouchID deviceId = 0;
     3.7 -    if (!SDL_GetTouch(deviceId)) {
     3.8 -        if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
     3.9 -             SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
    3.10 -        }
    3.11 -    }
    3.12 +	if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
    3.13 +		 SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
    3.14 +	}
    3.15  
    3.16      switch (touchState) {
    3.17          case QtWaylandTouchPointPressed:
     4.1 --- a/src/video/windows/SDL_windowsevents.c	Thu May 28 12:48:20 2015 -0700
     4.2 +++ b/src/video/windows/SDL_windowsevents.c	Thu May 28 12:55:01 2015 -0700
     4.3 @@ -849,10 +849,8 @@
     4.4                      PTOUCHINPUT input = &inputs[i];
     4.5  
     4.6                      const SDL_TouchID touchId = (SDL_TouchID)((size_t)input->hSource);
     4.7 -                    if (!SDL_GetTouch(touchId)) {
     4.8 -                        if (SDL_AddTouch(touchId, "") < 0) {
     4.9 -                            continue;
    4.10 -                        }
    4.11 +                    if (SDL_AddTouch(touchId, "") < 0) {
    4.12 +                        continue;
    4.13                      }
    4.14  
    4.15                      /* Get the normalized coordinates for the window */
     5.1 --- a/src/video/x11/SDL_x11xinput2.c	Thu May 28 12:48:20 2015 -0700
     5.2 +++ b/src/video/x11/SDL_x11xinput2.c	Thu May 28 12:55:01 2015 -0700
     5.3 @@ -197,9 +197,7 @@
     5.4                  continue;
     5.5  
     5.6              touchId = t->sourceid;
     5.7 -            if (!SDL_GetTouch(touchId)) {
     5.8 -                SDL_AddTouch(touchId, dev->name);
     5.9 -            }
    5.10 +            SDL_AddTouch(touchId, dev->name);
    5.11          }
    5.12      }
    5.13      X11_XIFreeDeviceInfo(info);