Question

When I'm compiling a simple example with SDL 2.0, after the command SDL_CreateWindow, this occurring the following error: "Passed a NULL mutex".

I'm using the static library project. Also I'm testing on OSX 10.8.3.

This inform missing something on the command line compilation?

Below is the command line to generate the program generation and code example.

Compiler:

clang++ -I "TestSDL/sdl/include" -Wall -c -x c++ -arch x86_64 -std=c++11 -stdlib=libc++ -MMD -MP -MF"src/main.d" -MT"src/main.d" -o "src/main.o" "../src/main.cpp"

Linker:

clang++ -L "TestSDL/sdl/lib" -arch x86_64 -stdlib=libc++ -Bstatic -framework GLUT -framework ForceFeedBack -framework IOKit -framework CoreAudio -framework CoreFoundation -framework Carbon -framework AudioUnit -framework AudioToolbox -framework OpenGL -framework Cocoa -o "TestSDL" ./src/main.o -lSDL2

Code:

#include "SDL.h"
#include <iostream>

using namespace std;

void checkSDLError(int line = -1)
{
    const char *error = SDL_GetError();

    if (*error != '\0') {
        cout << "SDL Error: " << error << " line: " << line << endl;
        SDL_ClearError();
    }
}

int main(int argc, char **argv)
{
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        return false;
    }

    SDL_Window * window = SDL_CreateWindow("Test SDL", SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED, 512, 512,
            SDL_WINDOW_SHOWN);
    checkSDLError(__LINE__);

    if (!window) {
        cout << "Unable to create window" << endl;
        return 1;
    }

    SDL_Event event;
    while (true) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
                case SDL_QUIT:
                    return 1;

                default:
                    break;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();
}
Was it helpful?

Solution 2

In conversation with the list (SDL http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org), I was informed in the same way that phpBoing reported. How have had several reports of this problem recently, an adjustment was made (http://hg.libsdl.org/SDL/rev/f8e3dcefed59) for this problem no longer occurs.

Thanks to all.

OTHER TIPS

Your doing it wrong. You should only call checkSDLError() if window == NULL.

http://wiki.libsdl.org/moin.fcg/SDL_CreateWindow

Returns the window that was created or NULL on failure; call SDL_GetError() for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top