sdl2 & win10 64bits problem lazarus / 39-Graphics ---------------------------------------------------------------------- fcu · 2024-11-07 14:03 Hi this simple program using sdl2 from (https://github.com/PascalGameDevelopment/SDL2-for-Pascal) crashes at startup , but if i explicitly specify opengl as default driver it works fine  can some one please confirm this on windows 64bits & sdl2 64bits Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$apptype gui}program demo;uses sdl2; var win : psdl_window; render: psdl_renderer; ev : tsdl_event; done: boolean = false; begin// uncomment this to work ok  //sdl_sethint(sdl_hint_rende r_driver,'opengl');  sdl_init(sdl_init_video); win := sdl_createwindow('demo',50,50,800,600,sdl_window_shown); render := sdl_createrenderer(win,-1,sdl_renderer_accelerated);  while not done do begin  if boolean(sdl_pollevent(@ev)) then  begin   case ev.type_ of    sdl_quitev:begin     done:= true;    end;   end;  end;  sdl_setrenderdrawcolor(render, 32, 38, 42, 255);  sdl_renderclear(render);  sdl_renderpresent(render); end;  sdl_destroy renderer(render); sdl_destroywindow(win);end. ---------------------------------------------------------------------- Fibonacci · 2024-11-07 14:19 Tested on Windows 10 x64 with 64 bit app. No crash. DLL version 2.0.20 as reported by SDL_GetVersion(). But with the line uncommented the window shows, hides instantly and then shows again after ~500ms maybe. ---------------------------------------------------------------------- MKGilby · 2024-11-07 14:22 Hi! I compiled and ran your code without problems on Windows 11 24H2 with Lazarus 4.0 rc1, SDL2-for-pascal (from GitHub) and SDL2.dll V2.30.6.0 ---------------------------------------------------------------------- fcu · 2024-11-07 15:30 Quote from: Fibonacci on November 07, 2024, 03:19:26 pmTested on Windows 10 x64 with 64 bit app. No crash. DLL version 2.0.20 as reported by SDL_GetVersion(). But with the line uncommented the window shows, hides instantly and then shows again after ~500ms maybe. strange  the same program in c++ works fine  in my win10 64bits this is the error message ---------------------------------------------------------------------- fcu · 2024-11-07 15:34 i think the default renderer driver in windows is direct3d  because if i set sdl_sethint(sdl_hint_render_driver,'direct3d'); the app crashes but works with sdl_sethint(sdl_hint_render_driver,'opengl'); ---------------------------------------------------------------------- DrakkTheSeafarer · 2024-11-07 21:31 you need to call SDL_Quit; https://wiki.libsdl.org/SDL2/SDL_Quit this should be called every time the program quits. you could use exceptions + try.. finally to clean up everything fine. https://www.freepascal-meets-sdl.net/error-handling/ greetings ---------------------------------------------------------------------- flowCRANE · 2024-11-18 01:23 @fcu: you are processing the SDL event queue incorrectly. In each frame of the game, you should process all events that exist in the queue, i.e. use a loop: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$apptype gui} program Demo;uses  SDL2;var  Window:   PSDL_Window;  Renderer: PSDL_Renderer;  Event:    TSDL_Event;  Done:   Boolean = False;begin  SDL_Init(SDL_INIT_VIDEO);   Window   := SDL_CreateWindow  ('Demo', 50, 50, 800, 600, SDL_WINDOW_SHOWN);  Renderer := SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);   while not Done do  begin    while SDL_PollEvent(@Event) = 1 do    case Event.Type_ of      SDL_QUITEV: Done := True;    end;     SDL_SetRenderDrawColor(Renderer, 32, 38, 42, 255);    SDL_RenderClear       (Renderer);    SDL_RenderPresent     (Renderer);  end;   SDL_DestroyRenderer(Renderer);  SDL_DestroyWindow  (Window);  SDL_Quit();end. Instead of the Done flag, you can simply jump to the label. After all, rendering the frame when the loop is about to end is unnecessary: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$apptype gui} program Demo;uses  SDL2;label  Cleanup;var  Window:   PSDL_Window;  Renderer: PSDL_Renderer;  Event:    TSDL_Event;begin  SDL_Init(SDL_INIT_VIDEO);   Window   := SDL_CreateWindow  ('Demo', 50, 50, 800, 600, SDL_WINDOW_SHOWN);  Renderer := SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED);   repeat    while SDL_PollEvent(@Event) = 1 do    case Event.Type_ of      SDL_QUITEV: goto Cleanup;    end;     SDL_SetRenderDrawColor(Renderer, 32, 38, 42, 255);    SDL_RenderClear     (Renderer);    SDL_RenderPresent     (Renderer);  until False; Cleanup:  SDL_DestroyRenderer(Renderer);  SDL_DestroyWindow  (Window);  SDL_Quit();end. Pro tip: start using the Shift key and format your code properly. I know it's a test program, but that's how you can recognize a professional, that they always write readable and formatted code. By the way, SDL3 is already available (preview version) — take an interest in it, because it is much better than SDL2 and soon it will be the standard. Of course, if you can write your own headers, because you won't find them on the net for a long time (I wrote these myself, for my own game — nothing difficult).