So I am developing a set of wrapping utilities for SDL2 but have come across a strange issue. Whenever I poll for errors using SDL_GetError at the end of a frame, if I am touching the trackpad I get the following strange error message: Unknown touch device id -1, cannot reset. This error in quotes only shows one result on google and it seems to be an issue with macOS though with only one occurrence it's hard to be sure.
Here's a minimum reproducible example:
#include <SDL2/SDL.h>
#include <stdio.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 100, 100, SDL_WINDOW_SHOWN);
while(1) {
SDL_Event e;
while(SDL_PollEvent(&e))
switch(e.type) {
case SDL_QUIT: {
SDL_DestroyWindow(window);
SDL_Quit();
exit(0);
break;
}
}
const char* err = SDL_GetError();
if(err[0]) {
printf("%s", err);
exit(-1);
}
}
}
I understand that this is a strange issue(and a potentially unanswerable one) so I really appreciate any answers or suggestions.
I am using a MacBook Pro 13-inch Mid 2012 running macOS Catalina(10.15.6). Compiled using clang 12.0.0
EDIT: I have downloaded the SDL2 source code to look for the error and the root cause seems to be this function:
static int
SDL_GetTouchIndex(SDL_TouchID id)
{
int index;
SDL_Touch *touch;
for (index = 0; index < SDL_num_touch; ++index) {
touch = SDL_touchDevices[index];
if (touch->id == id) {
return index;
}
}
return -1;
}
I am in the process of looking for why exactly this error is triggered and will update this post for any future people who encounter this error as well as filing a bug report to the SDL dev team