gpt4 book ai didi

c++ - SDL 2.0 -> 传递了一个 NULL 互斥体

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:41 26 4
gpt4 key购买 nike

当我使用 SDL 2.0 编译一个简单示例时,在命令 SDL_CreateWindow 之后,出现以下错误:“传递了一个 NULL 互斥量”。

我正在使用静态库项目。我也在 OSX 10.8.3 上进行测试。

此通知在命令行编译时遗漏了什么?

下面是生成程序的命令行和代码示例。

编译器:

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"

链接器:

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

代码:

#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();
}

最佳答案

你做错了。您应该调用 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.

关于c++ - SDL 2.0 -> 传递了一个 NULL 互斥体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16005970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com