Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. diff -Naur SDL2-2.0.10/src/haptic/linux/SDL_syshaptic.c SDL2-2.0.10.patched/src/haptic/linux/SDL_syshaptic.c
  2. --- SDL2-2.0.10/src/haptic/linux/SDL_syshaptic.c 2019-07-24 21:32:36.000000000 -0700
  3. +++ SDL2-2.0.10.patched/src/haptic/linux/SDL_syshaptic.c 2019-09-04 10:52:36.784736281 -0700
  4. @@ -974,6 +974,7 @@
  5. SDL_HapticEffect * data)
  6. {
  7. struct ff_effect linux_effect;
  8. + int retry_count = 0;
  9.  
  10. /* Create the new effect */
  11. if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) {
  12. @@ -981,10 +982,29 @@
  13. }
  14. linux_effect.id = effect->hweffect->effect.id;
  15.  
  16. +retry:
  17. /* See if it can be uploaded. */
  18. if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
  19. - return SDL_SetError("Haptic: Error updating the effect: %s",
  20. - strerror(errno));
  21. + int err = errno;
  22. + char const * err_str = strerror(err);
  23. +
  24. + /*
  25. + * For some strange and inexplicable reason, the kernel driver appears
  26. + * to "forget" about our effect for... "reasons."
  27. + *
  28. + * The only difference between creating a "new" effect and "updating" an
  29. + * effect, in the kernel API, is the use of the effect id of "-1" to
  30. + * request a new id.
  31. + *
  32. + * If we get EINVAL, try to reinitialize the effect by setting the index
  33. + * back to -1, but don't retry more than once. EINVAL is pretty vague
  34. + * and there could be other causes.
  35. + */
  36. + if ((err == EINVAL) && (retry_count++ == 0)) {
  37. + linux_effect.id = -1;
  38. + goto retry;
  39. + }
  40. + return SDL_SetError("Haptic: Error updating the effect: %s", err_str);
  41. }
  42.  
  43. /* Copy the new effect into memory. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement