Repository navigation
SDL software renderer fails with Floating Point Exception #56
Description
Activity
Interesting. We could sidestep this by hiding
SDL_CreateRenderer()behind a Pascal function that disables FPE, calls the SDL function, and restores the old exception mask - but I feel that this could be seen as invasive. The other issue is that we'd need to maintain a list of places that require this special handling.Free-Pascal-meets-SDL-Website commented
on Jun 5, 2022 CollaboratorMore actions@bunnylin Thanks for this detailed report and the solution.
hiding
SDL_CreateRenderer()behind a Pascal function [...] but I feel that this could be seen as invasive.@suve It seems to happen on calling
SDL_InitSubSystem(SDL_INIT_VIDEO)sometimes, too, hence wrapping this function alone would not cover all crashes. I agree about the invasiveness.Alternatively we could just simply add a Linux compiler hint referencing this issue for everybody to figure out themselves what is the best way to solve this in their projects. Downside: The hint will always be present in Linux then.
What do you guys think?
- added a commit that references this issue
on Jun 5, 2022 If there was a way to suppress the hint after the developer has addressed it, that would be perfect, but user-specified hints don't get a handy number that could be masked. The visibility may still be preferable... the hint only appears when the unit is compiled, and during normal development you're unlikely to rebuild every unit after each change.
Free-Pascal-meets-SDL-Website commented
on Jun 6, 2022 CollaboratorMore actionsThe visibility may still be preferable... the hint only appears when the unit is compiled, and during normal development you're unlikely to rebuild every unit after each change.
The downside is though, if someone compiled the units already (ignoring the hint) and later (days, months) runs into the crash he/she is likely not to remember the hint.
Well, alternatively we could use the
initilization partof theSDL2 unitto present the hint message. This would be a very verbose solution.Another alternative would be to introduce a compiler DEFINE for SDL2-For-Pascal hints to be spawned or suppress it. - I guess this would be too much for just one hint atm., but maybe for the future it may be useful to be introduced if further hints are necessary.
- addedwaiting 3rd partyWaiting for other project to fix somethingWaiting for other project to fix something
on Jun 17, 2022 - added a commit that references this issue
on Jul 15, 2022
This is mostly for visibility - I'm not sure where this would be best fixed.
It seems any SDL application compiled with Pascal will crash if trying to use software renderer video output, on Linux. To verify, run any SDL application with the environment variable
LIBGL_ALWAYS_SOFTWARE=1set. The failure happens either immediately onSDL_InitSubSystem(SDL_INIT_VIDEO), or when callingSDL_CreateRenderer. The error that appears can beEInvalidOp: Invalid floating point operationorEDivByZero: Division by zerodepending on environment.Doing this through GDB, I got this callstack pointing at the LLVMpipe software rasterizer:
So it's a problem in Mesa. This doesn't affect Pascal/SDL programs on Windows since users don't normally run Mesa there. An internet search turned up this bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3096
They say the FPE should normally not be enabled in the first place, and the caller should just disable the exception mode. A commenter notes that the affected software was made with Delphi, which suggests to me that Free Pascal and Delphi are both deliberately keeping this FPE enabled (and are unlikely to change that because it would break compatibility).
As a workaround, it's simple to disable the exception by applying a mask, via the Math unit: