SDL Error: Passed a NULL Mutex

Hello!

I just started using SDL the first time and i began with the OpenGL 3.2 context creation and i get the Error “SDL Eror: passed a NULL mutex”.

Code:

if (SDL_Init(SDL_INIT_VIDEO) < 0){ /* Initialize SDL’s Video subsystem /
sdldie(“Unable to initialize SDL”); /
Or die on error */
}

/* Request opengl 3.2 context.
 * SDL doesn't have the ability to choose which profile at this time of writing,
 * but it should default to the core profile */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

/* Turn on double buffering with a 24bit Z buffer.
 * You may need to change this to 16 or 32 for your system */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

/* Create our window centered at 512x512 resolution */
mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

if (!mainwindow) /* Die if creation failed */
    sdldie("Unable to create window");

[color=red]
checkSDLError(LINE);
[/color]
/* Create our opengl context and attach it to our window */
maincontext = SDL_GL_CreateContext(mainwindow);
checkSDLError(LINE);

/* This makes our buffer swap syncronized with the monitor's vertical refresh */
SDL_GL_SetSwapInterval(1);
return true;

The error is given in the red checkSDLError.

The tutorial is from: http://www.opengl.org/wiki/Tutorial1%3A_Creating_a_Cross_Platform_OpenGL_3.2_Context_in_SDL_(C_/_SDL)

Seems an odd error; at least in the Windows code I see no uses of a mutex in window creation, nor in SDL_GL_SetAttribute------------------------
Nate Fries

Yeah that was what i thought too, as i really only have this basic code without any direct use of the SDL_mutex stuff.

I grabbed the latest snapshot of SDL2 yesterday and used cmake+MinGW to build it in Code::Blocks. I am not sure if i made something wrong or maybe mixed some files of different SDL versions but i do not think so because i think i removed everything from the SDL1.2 from my system.

Did an API actually fail? We set the error message all over the place
for things that recovered from that error internally, and we don’t clear
it on successful API calls.

If it actually failed to make a window and reported that error, though,
that sounds like a bug.

–ryan.On 4/6/13 11:18 AM, Nathaniel J Fries wrote:

Seems an odd error; at least in the Windows code I see no uses of a
mutex in window creation, nor in SDL_GL_SetAttribute

No it successfully created a window and a OpenGL 3.2 context and everything seems fine - that is exactly why i wondered :slight_smile: If it would have failed to create the window i would have thought about doing something wrong but this way it feels like everything is ok and still it want to warn me about something.

I’m seeing this message too and since several months.
It is here immediately after SDL initialization :

SDL_Init(SDL_INIT_VIDEO);
printf("%s\n", SDL_GetError());

I thought it was just a small error caused by SDL2 being still in
development so I simply stopped calling SDL_GetError().
But as SDL2 release month has been set and the current .zip revision,
7046, still shows this message after init, I think maybe something must
be done ?

SDL_Init(SDL_INIT_VIDEO);
printf("%s\n", SDL_GetError());

I thought it was just a small error caused by SDL2 being still in
development so I simply stopped calling SDL_GetError().
But as SDL2 release month has been set and the current .zip revision,
7046, still shows this message after init, I think maybe something must
be done ?

That code is incorrect. It should be:

if (SDL_Init(SDL_INIT_VIDEO) == -1)
    printf("%s\n", SDL_GetError());

You should never check SDL_GetError() unless you’ve just had a
legitimate error reported by another SDL function call, as its contents
are meaningless in any other case. It’s not like glGetError()…it does
NOT signify an error in itself.

–ryan.

Oh thank you, I wasn’t aware about this difference with the OpenGL
GetError().

  1. SDL_Init don’t fail, returns 0.
  2. SDL_GetError is called. But it shouldn’t, because no SDL function failed.
  3. An error is reported

System is win7 64bits, SDL 7046 (and precedent ones) built with mingw.
Does anybody see this or are we just the only 2 stupid guys calling
functions when they shouldn’t ? :stuck_out_tongue:

You’re calling SDL_GetError when you shouldn’t :stuck_out_tongue:

Who wants to bet the error is caused by SDL_GetError itself?

2013/4/9, Thibault D’Archivio <thibault.darchivio at free.fr>:> Oh thank you, I wasn’t aware about this difference with the OpenGL

GetError().

  1. SDL_Init don’t fail, returns 0.
  2. SDL_GetError is called. But it shouldn’t, because no SDL function
    failed.
  3. An error is reported

System is win7 64bits, SDL 7046 (and precedent ones) built with mingw.
Does anybody see this or are we just the only 2 stupid guys calling
functions when they shouldn’t ? :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL’s error string is exactly like Windows or POSIX error code (but a string instead of an int); it being set might not indicate any actual error in an API.

In this case, passing a NULL pointer to a function that requires otherwise sounds like a segfault waiting to happen though.------------------------
Nate Fries

  1. SDL_Init don’t fail, returns 0.
  2. SDL_GetError is called. But it shouldn’t, because no SDL function failed.
  3. An error is reported

We set the error state lots of times internally. For example:

SDL_Init(SDL_INIT_AUDIO);

…will try to initialize XAudio2 on Windows, but if you’re running on
Windows XP, it won’t be available, so the XAudio2 support code in SDL
will set an error message to that effect. Then, before SDL_Init()
returns, SDL will try the DirectSound driver, which works fine, so
SDL_Init() will report success, but SDL_GetError() might still say
something like “XAudio2 isn’t available” … which is a meaningless
error message, because SDL_Init() correctly reported success.

So step 3: “An error is reported” isn’t right…no error was reported,
SDL_GetError() just had some random leftover junk in it.

–ryan.