我刚将C++游戏移植到OS X并首次运行时,在尝试呼叫SDL_SetVideoMode
时出现以下异常。SDL Video Init在Mac OS X上导致异常10.8
2012-09-28 15:01:05.437 SCRAsteroids [28595:707] *终止应用程序由于未捕获的异常 'NSInternalInconsistencyException',原因: *第一掷 '上线259创建CGSWindow错误(1000)'调用堆栈: ( 0的CoreFoundation 0x00007fff8b53b716 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff90e30470 objc_exception_throw + 43 2的CoreFoundation 0x00007fff8b53b4ec + [NSException提高:格式:] + 204 3了AppKit 0x00007fff8a26a579 _NSCreateWindowWithOpaqueShape2 + 655 4了AppKit 0x00007fff8a268d70 - [ NSWindow _commonAwake] + 2002 5 AppKit的0x00007fff8a2277e2 - [NSWindow _commonInitFrame:styleMask:背衬:延迟:] + 1763 6了AppKit 0x00007fff8a22692f - [NSWindow _initContent:styleMask:背衬:延迟:内容查看:] + 1568 7了AppKit 0x00007fff8a2262ff - [NSWindow initWithContentRect:styleMask:背衬:延迟:] + 45 8 libSDL-1.2.0.dylib 0x0000000107c228f6 - [SDL_QuartzWindow initWithContentRect:styleMask:背衬:延迟:] + 294 9 libSDL-1.2.0.dylib 0x0000000107c20505 QZ_SetVideoMode + 2837 10 libSDL-1.2.0名为.dylib 0x0000000107c17af5 SDL_SetVideoMode + 917个 11 SCRAsteroids 0x0000000107be60fb _ZN11SDLGraphics4initEP6IWorldii + 291 ) 的libC++ abi.dylib:终止称为抛出异常 中止陷阱:6
我的初始化代码如下所示:
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return false;
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
fprintf(stderr, "Video query failed: %s\n",
SDL_GetError());
return false;
}
/* the flags to pass to SDL_SetVideoMode */
videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */
/* This checks to see if surfaces can be stored in memory */
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;
if (w == 0) {
widthViewport = videoInfo->current_w;
heightViewport = videoInfo->current_h;
cout << "Will use full screen resolution of ";
videoFlags |= SDL_FULLSCREEN;
} else {
cout << "Will use full user supplied resolution of ";
widthViewport = w;
heightViewport = h;
videoFlags |= SDL_RESIZABLE; /* Enable window resizing */
}
cout << widthViewport << "x" << heightViewport << "\n";
/* This checks if hardware blits can be done */
if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
/* Sets up OpenGL double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
/* get a SDL surface */
surface = SDL_SetVideoMode(widthViewport, heightViewport,
SCREEN_BPP, videoFlags);
它进入去年SDL调用,并抛出上述异常。我已经在全屏和可调整大小的窗口模式下尝试过它,同样的事情。
我在命令行上构建我的应用程序老派,而不是使用Xcode。
请问您的主文件包括SDL.h?如果是这样,你的main()将被重命名为你! – ScrollerBlaster