本文介绍了SDL2 无效的渲染器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我这里有一个 SDL2 错误,我想要一些验证.当我创建渲染器时,它是无效的,因此我无法初始化 SDL_ttf.这是一个快速演示程序,展示了我的 xubuntu 14.04 发行版上的问题.我的显卡是 NVIDIA GTX 550 Ti.驱动程序版本 331.113 专有,已测试.

I believe I have an SDL2 bug here and I wanted some verification. When I create a renderer it is invalid and I cannot initialize SDL_ttf because of this. Here is a quick demo program that exhibits the issue on my xubuntu 14.04 distribution. My graphics card is an NVIDIA GTX 550 Ti. Driver version 331.113 proprietary, tested.

#include <SDL2/SDL.h>

#include <string>
#include <stdexcept>
#include <iostream>

using namespace std;

int main() {
SDL_Window* _window;
SDL_Renderer* _renderer;

if( SDL_Init( SDL_INIT_EVERYTHING ) != 0 ) {
    string error( SDL_GetError() );
    throw runtime_error( "SDL could not initialize! SDL Error: " + error );
}

_window = SDL_CreateWindow( "Conscious", SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN );
if( _window == NULL ) {
    string error( SDL_GetError() );
    throw runtime_error( "Window could not be created! SDL Error: " + error );
}

_renderer = SDL_CreateRenderer( _window , -1,
        SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( _renderer == NULL ) {
    string error( SDL_GetError() );
    throw runtime_error( "Renderer could not be created! SDL Error: " + error );
}

cout << SDL_GetError() << endl;

return 0;
}

告诉我你的想法!

谢谢,乔纳森

--编辑--

如果你去掉 SDL_image 和 SDL_ttf,渲染器仍然返回无效.在具有相同硬件的 Windows 上也不会发生这种情况.如果这不是一个错误,有人请解释一下这样一个简单的例子可能有什么问题吗?

If you take out SDL_image and SDL_ttf the renderer is still returned as invalid.Also this does not happen on windows with the same exact hardware. If this is not a bug would somebody please explain what could be wrong with such a simple example?

--编辑编辑--此代码在我的系统上打印出无效渲染器".如果您有 SDL2,请运行它,如果您也有,请告诉我.

--EDIT EDIT--This code prints out "Invalid renderer" on my system. If you have SDL2 please run it and let me know if you do too.

推荐答案

虽然它确实会产生 'Invalid renderer' 消息,但这不是问题,因为正如 SDL_GetError 文档所述 You必须检查 SDL 函数调用的返回值以确定何时适当地调用 SDL_GetError().,而 SDL 没有给您在 GetError 中查找错误描述的理由.

While it is indeed produces 'Invalid renderer' message, it isn't a problem because as SDL_GetError documentation states You must check the return values of SDL function calls to determine when to appropriately call SDL_GetError()., and SDL gave you no reason to look for error description in GetError.

顺便说一下,为什么会这样:

Why it happens, by the way:

Breakpoint 1, 0x00007ffff7b00e90 in SDL_SetError_REAL () from /usr/lib64/libSDL2-2.0.so.0
(gdb) backtrace
#0  0x00007ffff7b00e90 in SDL_SetError_REAL () from /usr/lib64/libSDL2-2.0.so.0
#1  0x00007ffff7b8f124 in SDL_GL_GetProcAddress_REAL () from /usr/lib64/libSDL2-2.0.so.0
#2  0x00007ffff7b8f80b in SDL_GL_GetAttribute_REAL () from /usr/lib64/libSDL2-2.0.so.0
#3  0x00007ffff7b41bcf in GL_CreateRenderer () from /usr/lib64/libSDL2-2.0.so.0
#4  0x00007ffff7b3b66c in SDL_CreateRenderer_REAL () from /usr/lib64/libSDL2-2.0.so.0
#5  0x0000000000401383 in main ()

GL_CreateRenderer 调用 SDL_GetAttribute 来获取上下文版本等,它会尝试加载 GL 函数,这需要主动渲染器,但它还没有.虽然不是最令人赏心悦目的解决方案,但它运行良好并且不是错误.您在 Windows 上没有它的可能原因是例如因为它使用不同的渲染器(d3d?).

GL_CreateRenderer calls SDL_GetAttribute to get context version and such, which tries to load GL functions, which requires active renderer, but it isn't there yet. While not most eye-pleasant solution, it works well and it isn't a bug. Probable reason why you don't have it on windows is e.g. because it uses different renderer (d3d?).

这篇关于SDL2 无效的渲染器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:45
查看更多