The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
sdl2/nvidia crashes when SDL_CreateRenderer
pik33


Joined: 25 Nov 2015
Posts: 10
I started to test SDL 2.0 in Windows. I have 2 computers, both with AMD FX8320 CPU running Windows 8.0 x64; the graphic card in the first of them is NVidia GeForce GT760, in the second there is AMD 7950.

I use Lazarus (FreePascal) for programming.

I wrote this procedure

Code:

begin
  SDL_Init( SDL_INIT_VIDEO );
  sdlWindow1 := SDL_CreateWindow( 'Window1', 0, 0, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
  il:=SDL_GetNumRenderDrivers;
  for i:=0 to il-1 do begin
    SDL_GetRenderDriverInfo(i,@ri);
    memo1.lines.add(ri.name+' '+inttostr(ri.flags));                //show renderers names and flags
  end;

  try
    sdlRenderer := SDL_CreateRenderer( sdlWindow1, 1, 0 );  // experiment here with renderer ID and flags
  except
    SDL_DestroyTexture( sdlTexture1 );
    SDL_DestroyRenderer( sdlRenderer );
    SDL_DestroyWindow ( sdlWindow1 );
    button1.caption:=inttostr(il);
    sdl_quit;
  end;

  sdlTexture1 := IMG_LoadTexture( sdlRenderer, 'D:\ada21.jpg' );
  sdlTexture2 := IMG_LoadTexture( sdlRenderer, 'D:\1.jpg' );
  for i:=1 to 100 do begin
    SDL_RenderCopy( sdlRenderer, sdlTexture1, nil, nil );
    SDL_RenderPresent (sdlRenderer);
    SDL_RenderCopy( sdlRenderer, sdlTexture2, nil, nil );
    SDL_RenderPresent (sdlRenderer);
    end;

  sdl_delay(1000);
  SDL_DestroyTexture( sdlTexture1 );
  SDL_DestroyTexture( sdlTexture2 );
  SDL_DestroyRenderer( sdlRenderer );
  SDL_DestroyWindow ( sdlWindow1 );
  button1.caption:=inttostr(il);
  sdl_quit;
end;


to experiment with renderers and check if they can wait for vsync.

With AMD 7950 all went OK. There were 4 renderers, directx, opengl, opengles, software. Both directx and opengl works as expected.

On Nvidia machine opengl works, but directx (it is default renderer) crashes in this line:

Code:
    sdlRenderer := SDL_CreateRenderer( sdlWindow1, 1, 0 );


giving segmentation fault in 32 bit environment and division by 0 in 64 bit.

The SDL fullscreen windows is created and captured the mouse in this moment, but not displayed yet... I can still see a windows desktop but it doesn't respond. Then I cannot debug the code any more or even kill the process. The only solution is ctrl-alt-del, then logout. Alt-F4 does nothing. (How to kill sdl program in Windows when it hangs in fullscreen mode? In Linux I always have ctrl-alt-f2, then ps and kill -9... )

So I added this try..except..end construct which works when run standalone .exe (the program does nothing when directx renderer is selected so I can eventualy switch to opengl) but either I have to set something I don't know or there is a bug somewhere.

I found the directx version in the computer with NVidia card is 11.0 and not 11.1 - can it be the source of this problem? Broken nvidia drivers maybe?

So I will try to reinstall nvidia graphic drivers, but this I can do tomorrow. Maybe there is a known problem with SDL/directx/nvidia combination?
pik33


Joined: 25 Nov 2015
Posts: 10
Of course code which crashes is

Code:
 sdlRenderer := SDL_CreateRenderer( sdlWindow1, -1, 0 );


not
Code:
 sdlRenderer := SDL_CreateRenderer( sdlWindow1, 1, 0 );
which creates working OpenGL renderer.
pik33


Joined: 25 Nov 2015
Posts: 10
Solved. Something was broken with NVidia settings. Solution was "clean reinstall" Nvidia drivers with resetting to factory defaults.