I have been using SDL3 for creating basic 2D games before. I have formatted and installed a fresh Ubuntu 24.04.1 today and SDL3 seems to have issues initializing SDL_INIT_VIDEO.
Unable to initialize SDL:
SDL_GetError() returns nothing. I am in Ubuntu24.04.1 and using Nvidia 560.35.03 driver.
Any help is greatly appreciated. Thanks in advance.
Awesome. It works. Thanks a ton. I forgot to check the API for SDL_Init, because I have been writing in SDL3 for few months now, I was so confident, I read the SDL_Init thoroughly. Thanks again for taking your time.
To be honest this change is a huge PITA when porting existing SDL2 code - which I just did with dhewm3.
It compiles just fine, but silently breaks… and some of those functions can cause more subtle breakage than “game aborts at start because SDL_Init() appeared to fail”.
It would be nice to have one list with all functions where the return value changed from int to bool, or similar changes to the function signature that are not caught by the compiler (like switched arguments that still have a compatible type) - not sure if such changes exist though, I think so far I’ve only run into the “returns true instead of 0 on success now” issue.
Would be nice to have a simple list that one can use with a script that greps for those functions in your code so one knows where to check. And it should contain both the old and the new names - remember that many codebases will continue to support SDL2 for some time, so people will use SDL_oldnames.h (or similar custom defines).
Would be even nicer if SDL provided not just a list but such a script
I haven’t used that coccinelle script because as far as I understood it would rename all the functions etc - I ported manually so I could ensure backwards compatibility.
But yes, the part of the script you posted might be useful to identify the function calls with this particular problem, thanks!
I guess I’ll toy around with it tomorrow, I’ve never used coccinelle.
In C99, true and false are defined as macros inside <stdbool.h>. This is what SDL3 uses now, if available, otherwise it defines them. SDL_bool doesn’t exist anymore.
I tried to turn the coccinelle script into something minimal that only adds a comment to the affected function calls, but it didn’t seem to work too well, missed some cases (maybe it isn’t very good with code hidden behind #if/#else?).
I created a list of all affected functions (based on the list in the coccinelle script, but also added the corresponding SDL2 function names based on SDL_oldnames.h) which can be used with grep to find all potentially affected cases in your code. You’ll have to check each returned line manually, but at least then you know where to look (and can already ignore all the function calls where you don’t check the return value at all ;)).
$ cd /path/to/your/source
$ grep -rn -f /path/to/sdl_boolretfns.txt
You could additionally use greps --exclude, --exclude-dir and/or --include options in case you get too many results from files you don’t care about, see man grep.
One weird thing about --exclude-dir is that it can only be the name of one directory, e.g. --exclude-dir=libs, while --exclude-dir=libs/imgui does not work.