From 9a69cdaf9a5e0de1a8532d85f3ef6175273b7644 Mon Sep 17 00:00:00 2001 From: Jim Grandpre Date: Thu, 29 Jul 2010 12:24:34 -0400 Subject: [PATCH] Prevented SDL_SendDown from sending on nonexistent touch devices. --- src/events/SDL_touch.c | 21 +++++++++++++++++++-- src/video/cocoa/SDL_cocoawindow.m | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 6cb4964ea..e0b74141e 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -312,6 +312,10 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu int posted; SDL_Touch* touch = SDL_GetTouch(id); + if(!touch) { + return SDL_TouchNotFoundError(id); + } + if(down) { SDL_Finger *finger = SDL_GetFinger(touch,fingerid); if(finger == NULL) { @@ -374,7 +378,10 @@ SDL_SendTouchMotion(int id, int fingerid, int relative, int yrel; int x_max = 0, y_max = 0; - if (!touch || touch->flush_motion) { + if (!touch) { + return SDL_TouchNotFoundError(id); + } + if(touch->flush_motion) { return 0; } @@ -459,8 +466,9 @@ SDL_SendTouchButton(int id, Uint8 state, Uint8 button) int posted; Uint32 type; + if (!touch) { - return 0; + return SDL_TouchNotFoundError(id); } /* Figure out which event to perform */ @@ -510,4 +518,13 @@ SDL_GetTouchName(int id) return touch->name; } +int SDL_TouchNotFoundError(int id) { + printf("ERROR: Cannot send touch on non-existent device with id: %i make sure SDL_AddTouch has been called\n",id); + printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch); + int i; + for(i=0;i < SDL_num_touch;i++) { + printf("ERROR: %i\n",SDL_touchPads[i]->id); + } + return 0; +} /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index b67f8340b..ea0ee9bf4 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -313,7 +313,7 @@ - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event touch.pressureres = touch.pressure_max - touch.pressure_min; if (SDL_AddTouch(&touch, "") < 0) { - return; + continue; } } float x = [touch normalizedPosition].x;