问题
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;
}
Let me know what you think!
Thanks, Jonathon
--EDIT--
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?
--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.
回答1:
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
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?).
来源:https://stackoverflow.com/questions/31628174/sdl2-invalid-renderer