Author Topic: FPC and SDL2 Why does this crash  (Read 306 times)


  • Newbie
  • Posts: 2
FPC and SDL2 Why does this crash
« on: December 31, 2018, 02:42:19 am »
Hi Everyone,

I have been trying to self-teach myself how to develop a game and I am using Free Pascal and SDL2 2.0.9 to learn.  I am trying to get my project to work in Ubuntu Linux 18 but it crashes with a runtime error 200 whenever I start it up.  The project works just fine on Windows 10.

I've stripped the code down to just the barebone initialization of SDL2 and it still crashes in Linux.  I then made the same code in C on the same Linux, and for some reason the identical C code works just fine but the Pascal version crashes.

I don't know if I am doing something wrong or if somehow maybe there is a problem with Free Pascal but I am at a loss as to how to resolve the crash.  I will paste the code below.  The headers I am using can be found at the following link:

I looked at the headers and I didn't see anything wrong but I am mostly a beginner so maybe the headers are not accurate or I am not using a compiler options or something?  The code itself does not seem to return any errors.

Thank you to anyone who is willing to help me figure this out!  This is the Pascal code (crashes) while C version doesn't:

Code: Pascal  [Select]
  1. Program testsdl;
  3. Uses
  4.         SDL2 in 'SDL2/sdl2.pas';
  6. Var
  7.         Window   : PSDL_Window;
  8.         Renderer : PSDL_Renderer;
  9. Begin
  10.         If SDL_Init(SDL_INIT_VIDEO) < 0 Then Begin
  11.                 WriteLn ('Error init video');
  12.                 Exit;
  13.         End;
  15.         Window := SDL_CreateWindow('SDL_RenderClear',
  17.                 640, 480,
  18.                 SDL_WINDOW_FULLSCREEN_DESKTOP);
  20.         If Window = NIL Then Begin
  21.                 WriteLn('Error creating window');
  22.                 Halt;
  23.         End;
  25.         Renderer := SDL_CreateRenderer(Window, -1, 0);
  27.         If Renderer = NIL Then Begin
  28.                 WriteLn('Error creating renderer');
  29.                 Halt;
  30.         End;
  32.         SDL_RenderClear(Renderer);
  33.         SDL_RenderPresent(Renderer);
  35.         SDL_Delay(5000);
  37.         SDL_Quit();
  38. End.


  • Newbie
  • Posts: 3
  • ookami
    • Website
Re: FPC and SDL2 Why does this crash
« Reply #1 on: December 31, 2018, 01:58:06 pm »
I remember having a similar problem on Linux with SDL2. Try adding this as the first line in your uses clause:

{$IFDEF UNIX}cthreads,{$ENDIF}


  • Newbie
  • Posts: 2
Re: FPC and SDL2 Why does this crash
« Reply #2 on: January 04, 2019, 12:34:39 am »
Thank you for the response.  I have tried to add the CThreads into the program but it still seems to crash in the same way.  I managed to narrow it down to the SDL_RenderClear function.  If I comment that out everything else seems to run fine and of course the C version works with the RenderClear.

I've since tried to add in some code to print out the available drivers and that part also crashes but with a different 216 error.

I just cannot seem to get it to work outside of C.


  • Hero Member
  • *****
  • Posts: 7996
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC and SDL2 Why does this crash
« Reply #3 on: January 04, 2019, 01:21:10 am »
I stumble upon this thread and I tried one of the solution:
Code: [Select]
$ SDL_RENDER_DRIVER=opengl ./testsdl
Seems working.