I am trying to use SDL2 on a Mac. My code is the most basic thing as follows:
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, const char * argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
}
SDL_Quit();
return 0;
}
As soon as I run it I get this message: flock failed to lock maps file: errno = 35
and some errors apparently related to audio (the audio errors don’t appear if you only use SDL_INIT_VIDEO.
I’ve seen in forums all over that it is caused by having two instances of the program running, and that restarting and cleaning will fix it. Except it doesn’t, I have restarted a million times and I still get the error. There’s another post here describing the same situation also on Reddit and Stack Overflow. None of them have answers other than restarting and cleaning the cache.
I have a feeling it’s an Xcode issue since most questions about it are less than a year old, also I’ve seen some other questions regarding other libraries in Command Line Tool
projects.
Note that initialization itself doesn’t fail as the error message doesn’t appear in the log. I tried just ignoring it and go ahead and create a window like this:
int main(int argc, const char * argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
SDL_Log("Could not initialize SDL: %s\n", SDL_GetError());
}
SDL_Window *window = SDL_CreateWindow("Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_GRABBED);
if (window == NULL) {
SDL_Log("Could not create window: %s\n", SDL_GetError());
}
SDL_Delay(10000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
The thing is the window is never displayed, it also doesn’t throw an error as the call to SDL_CreateWindow
does return a valid pointer instead of NULL
, the window is aparently created it just won’t appear (yeah I checked and it was not hidden/minimized). My guess is: it is related to the file that couldn’t be locked.
Also I have only system apps running, so I don’t think another SDL app could be trying to access the same file (and AFAIK it shouldn’t really be a problem if there were any).
I am running Catalina 10.15.5 with Xcode 11.6 and SDL 2.0.12. Currently I am compiling SDL myself and linking to the built framework, I also tried using both prebuilt (runtime and development) versions of SDL and the same thing (and some others) happened.