首页 > 解决方案 > Mojave 上 SDL_CreateRenderer() 的“无效上下文 0x0”?

问题描述

我已经构建了一个基本的 SDL 2 C++ 程序,它可以创建一个窗口并显示一个图像。我正在使用 Mac OS Mojave 和 Xcode。一切正常,但我收到以下错误消息:

2018-12-28 11:49:38.602582-0700 SDLTest[76555:7241475] [SDLTest]  
CGContextSetFillColorWithColor: invalid context 0x0. If you want to 
see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE 
environmental variable.
2018-12-28 11:49:38.602623-0700 SDLTest[76555:7241475] [SDLTest] 
CGContextGetCompositeOperation: invalid context 0x0. If you want to 
see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE 
environmental variable.
2018-12-28 11:49:38.602640-0700 SDLTest[76555:7241475] [SDLTest] 
CGContextSetCompositeOperation: invalid context 0x0. If you want to 
see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE  
environmental variable.
2018-12-28 11:49:38.602653-0700 SDLTest[76555:7241475] [SDLTest] 
CGContextFillRects: invalid context 0x0. If you want to see the 
backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental 
variable.
2018-12-28 11:49:38.602666-0700 SDLTest[76555:7241475] [SDLTest]
CGContextSetCompositeOperation: invalid context 0x0. If you want to
see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE  
environmental variable.

当我添加对 SDL_CreateRenderer() 的调用时会创建错误。它们是在启动时生成的,并且在我调整窗口大小时再次生成。

我没有找到任何导致这些错误的 SDL_CreateRenderer() 示例。我听说如果一切正常,可以忽略这些错误,但我宁愿现在处理它们。

知道是什么导致了这些错误,或者如何处理它们?

我的代码:

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
    cout << "SDL could not initialize: " << SDL_GetError();
}

//Create window
SDL_Window *window = NULL;
window = SDL_CreateWindow( "SDLTest", 
                           SDL_WINDOWPOS_CENTERED,  
                           SDL_WINDOWPOS_CENTERED,
                           640, 480,
                           SDL_WINDOW_RESIZABLE |  
                           SDL_WINDOW_ALLOW_HIGHDPI | 
                           SDL_WINDOW_SHOWN);
if( window == NULL 
{
    cout << "Window could not be created: " 
         << SDL_GetError() << endl;
}

//Create renderer - Errors appear after adding these lines
SDL_Renderer *renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL )
{
    cout << "Renderer could not be created: " 
         << SDL_GetError() << endl;
}

标签: c++xcodemacossdl-2macos-mojave

解决方案


推荐阅读