I have a SDL2 project that I built so far successfully in an Ubuntu 15.04 VM. Now I assembled a new Desktop and just freshly installed Ubuntu 15.04 there as well as Code::Blocks and SDL2. I cloned my git repository, opened the Code::Blocks project and get the following error from SDL_GetError():
I already tried substituting SDL_RENDERER_SOFTWARE by SDL_RENDERER_ACCELERATED, but the error is the same. Am I missing something obvious here? Could someone please give me a nudge in the right direction?
I’m sorry, I thought that the error message might be enough already. Here’s the full code up to the point where the error happens (all code after includes about 12 own classes and is not called up to that point):
int main( int argc, char* args[] )
{
//Start up SDL and create window
if( !init() )
{
printf( “Failed to initialize!\n” );
}
else
{
SDL_Renderer *ren = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_SOFTWARE);
if (ren == nullptr){
SDL_DestroyWindow(gWindow);
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
SDL_Quit();
return 1;
}
//Here comes a lot of SDL unrelated code that’s never executed because the ren is null and the error gets caught
My guess is that SDL_GetWindowSurface() has to create a hidden renderer so
you can access the window like a surface. If you’re using the renderer
API, don’t use SDL_GetWindowSurface().
SDL_GetWindowSurface calls SDL_CreateWindowFramebuffer which calls internal CreateWindowFramebuffer (SDL_CreateWindowTexture) in which SDL_Renderer is created.