SDL2-for-Pascal icon indicating copy to clipboard operation
SDL2-for-Pascal copied to clipboard

error with sdl2 64bits on windows 10 64bits

Open fochen79 opened this issue 1 year ago • 9 comments

Hi this simple code compiles ok but crashes when runing , but if i uncomment the lines it works ok can you please try it on windows 10 64bits & sdl2 64bits & fpc 3.2 64bits ` {$mode objfpc} {$apptype gui} program demo; uses sdl2;

var win : psdl_window; render: psdl_renderer; ev : tsdl_event; done: boolean = false;

begin //sdl_sethint(sdl_hint_render_driver,'opengl'); sdl_init(sdl_init_video); win := sdl_createwindow('FPC demo',50,50,320,200,sdl_window_shown {or sdl_window_opengl} ); 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_destroyrenderer(render); sdl_destroywindow(win); end.

`

fochen79 avatar Nov 14 '24 16:11 fochen79

this is the error message sdl_error

fochen79 avatar Nov 14 '24 16:11 fochen79

Can you try compiling with -gl?

suve avatar Nov 14 '24 17:11 suve

yes i tried , the line 17 is render := sdl_createrenderer(win,-1,sdl_renderer_accelerated);

error

fochen79 avatar Nov 14 '24 19:11 fochen79

also i tried using gdb it show this : gdb

fochen79 avatar Nov 14 '24 19:11 fochen79

Hmm. This seems very similar to #56. We thought that it's a Linux-only issue, but maybe it happens on Windows as well?

Please check if this will work:

  1. Add uses Math to your code
  2. Add the following two variables: OldMask, NewMask: TFPUExceptionMask;
  3. Add the following code before the SDL_CreateRenderer call:
OldMask := Math.GetExceptionMask();
NewMask := OldMask;
Include(NewMask, exInvalidOp);
Include(NewMask, exZeroDivide);
Math.SetExceptionMask(NewMask);
  1. And then after the renderer is created:
Math.SetExceptionMask(OldMask);

suve avatar Nov 14 '24 20:11 suve

thanks , yes it works with this workaround

fochen79 avatar Nov 15 '24 12:11 fochen79

dose this mean i will use this workaround always in win10 64bits ?

fochen79 avatar Nov 15 '24 12:11 fochen79

Well, this bug is specific to software renderers - so if you want to support running the program using SDL2's software renderer, then yes, the workaround will be needed.

I'll try poking around with a debugger a bit to see if I can spot any issues in SDL2 code. If not, I'll open an issue upstream; maybe someone there will have a better idea.

suve avatar Nov 16 '24 12:11 suve

ok , but the software renderer works fine without problem the problem is with SDL_RENDERER_ACCELERATED ,

fochen79 avatar Nov 16 '24 13:11 fochen79