Mercurial > sdl-ios-xcode
comparison src/events/SDL_touch.c @ 5126:d79ff339d1f2
Fixed bug #1056 (Frequent crashes in Touch events by simply touching the screen)
Joseba GarcĂa Echebarria 2010-12-15 01:55:22 PST
I believe the crash is caused by a check not being performed on wether an
SDL_Touch element is NULL before using it in the SDL_SendTouchMotion function
in src/events/SDL_touch.c around line 400.
Judging from the rest of the code, there's a missing
if (!touch) {
return 0;
}
before using "touch" as SDL_GetFinger(), SDL_GetFingerIndexId() use
touch->num_fingers without checking.
I can attach a patch if you like. It seems pretty straightforward, though.
I have yet to discover why touch is being returned as NULL as this error is
only triggered when an actual gesture has been performed, maybe something
related to SDL_AddTouch()?
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 28 Jan 2011 10:21:58 -0800 |
parents | 8bf5781fc582 |
children | b530ef003506 |
comparison
equal
deleted
inserted
replaced
5125:dc0dfdd58f27 | 5126:d79ff339d1f2 |
---|---|
395 int | 395 int |
396 SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, | 396 SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, |
397 float xin, float yin, float pressurein) | 397 float xin, float yin, float pressurein) |
398 { | 398 { |
399 int index = SDL_GetTouchIndexId(id); | 399 int index = SDL_GetTouchIndexId(id); |
400 SDL_Touch *touch = SDL_GetTouch(id); | 400 SDL_Touch *touch; |
401 SDL_Finger *finger = SDL_GetFinger(touch,fingerid); | 401 SDL_Finger *finger; |
402 int posted; | 402 int posted; |
403 Sint16 xrel, yrel; | 403 Sint16 xrel, yrel; |
404 float x_max = 0, y_max = 0; | 404 float x_max = 0, y_max = 0; |
405 Uint16 x; | 405 Uint16 x; |
406 Uint16 y; | 406 Uint16 y; |
407 Uint16 pressure; | 407 Uint16 pressure; |
408 | 408 |
409 touch = SDL_GetTouch(id); | |
409 if (!touch) { | 410 if (!touch) { |
410 return SDL_TouchNotFoundError(id); | 411 return SDL_TouchNotFoundError(id); |
411 } | 412 } |
412 | 413 |
413 //scale to Integer coordinates | 414 //scale to Integer coordinates |
416 pressure = (Uint16)((yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); | 417 pressure = (Uint16)((yin+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres)); |
417 if(touch->flush_motion) { | 418 if(touch->flush_motion) { |
418 return 0; | 419 return 0; |
419 } | 420 } |
420 | 421 |
422 finger = SDL_GetFinger(touch,fingerid); | |
421 if(finger == NULL || !finger->down) { | 423 if(finger == NULL || !finger->down) { |
422 return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); | 424 return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein); |
423 } else { | 425 } else { |
424 /* the relative motion is calculated regarding the last position */ | 426 /* the relative motion is calculated regarding the last position */ |
425 if (relative) { | 427 if (relative) { |
494 finger->last_y = finger->y; | 496 finger->last_y = finger->y; |
495 finger->last_pressure = finger->pressure; | 497 finger->last_pressure = finger->pressure; |
496 return posted; | 498 return posted; |
497 } | 499 } |
498 } | 500 } |
501 | |
499 int | 502 int |
500 SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) | 503 SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button) |
501 { | 504 { |
502 SDL_Touch *touch = SDL_GetTouch(id); | 505 SDL_Touch *touch; |
503 int posted; | 506 int posted; |
504 Uint32 type; | 507 Uint32 type; |
505 | 508 |
506 | 509 |
510 touch = SDL_GetTouch(id); | |
507 if (!touch) { | 511 if (!touch) { |
508 return SDL_TouchNotFoundError(id); | 512 return SDL_TouchNotFoundError(id); |
509 } | 513 } |
510 | 514 |
511 /* Figure out which event to perform */ | 515 /* Figure out which event to perform */ |