-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Added SDL_HINT_INVALID_PARAM_CHECKS and SDL_HINT_INVALID_PARAM_ACTION #13943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I've currently implemented it for the renderer APIs, but if we like this direction, I can pretty easily extend it to other subsystems. @icculus, @sezero, @madebr, @smcv, @AntTheAlchemist, @mechakotik, @bjorn, thoughts? BTW, @madebr, @icculus, I noticed that asserts aren't enabled in debug builds. The logic we use here isn't correct for cmake on Windows: Lines 97 to 104 in de1b52f
It turns out that Microsoft Visual Studio doesn't actually define _DEBUG when /MDd is passed on the command line, that just appears to be a convention for default projects. The approach I took in SDL_internal.h is the only one that works on Windows for both CMake and Visual Studio. Since keying off of NDEBUG is the convention for disabling asserts in assert.h, we probably want to use that for SDL_assert() as well.
|
Very nice. I see NDEBUG enables checking at hint level. And do I see that Should we have a comprehensive list of preprocessor options for SDL_LEAN_AND_MEAN / SDL_GPU_DISABLED & co? |
While I think it's great to see such a comprehensive change to address this issue, speaking for myself I think it's unfair to supersede PR #13213 by @mechakotik in this way. They have already put in significant effort and have been waiting for feedback for months. Their PR solved the issue quite elegantly by reusing the
I think assertion-enabled debug and fast-but-crashing release builds matches the generally expected defaults. |
SDL_assert_always(!(invalid)); \ | ||
if (SDL_invalid_param_action == SDL_INVALID_PARAM_ACTION_ABORT) { \ | ||
if (invalid) { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This evaluates invalid
three times, is that ever going to be a problem? If yes, then it should assign the result of evaluating invalid
to a local variable, and then use that local variable everywhere.
If there's a concern about performance, it might be worthwhile to introduce an equivalent of GLib's Another technique I've seen in other libraries is to do the actual parameter check inline, but offload all the handling of what happens when it wasn't true into some other internal function, like this pseudocode using gcc statement expressions:
(I can't immediately see how to do this in portable C though...) |
b997a58
to
3045f3d
Compare
@icculus, sanity check here? |
@madebr, did I do the CMake changes correctly? They appear to work here in Visual Studio. |
7b8d5a6
to
fbca23d
Compare
Wouldn't it be cleaner to bypass validity checks inside Also, is NULL check bypass really useful? NULL check is one integer comparison that costs nothing compared to amount of work most SDL functions do, so performance benefit of disabling them would probably be unnoticeable. You also check whether |
This seems super heavy-weight. Is this something we really want to do, vs just having if statements that return an error? |
I still vote for all the checks just to be wrapped behind a compile-time option. I don't even want any parameters checked for NULL. My apps already know parameters are valid, and doesn't need the same object checked thousands of times each frame - hundreds of thousands per second - this is a significant performance hit. |
d867de1
to
79729ff
Compare
About Disabling all assertions when Configuring the assert levels depending on #if defined(NDEBUG)
#define SDL_ASSERT_LEVEL 0 // enabled: none | Disabled: SDL_assert_paranoid SDL_assert SDL_assert_release
#elif defined(DEBUG) || defined(_DEBUG)
#define SDL_ASSERT_LEVEL 2 // enabled: SDL_assert_release SDL_assert | Disabled: SDL_assert_paranoid
#else
#define SDL_ASSERT_LEVEL 1 // enabled: SDL_assert_release | Disabled: SDL_assert_paranoid SDL_assert
#endif If we really want to keep |
Yes, SDL_assert_release() should be enabled when NDEBUG is defined. |
This disables SDL parameter validation for release builds by default and adds an assertion when parameter validation fails in debug builds.
For debug builds, we'll do full parameter checking and assert if that fails. For release builds, we'll do fast parameter checking and return if that fails.
79729ff
to
e9ee01e
Compare
Okay, thanks for the feedback, everyone. I'm going to mark this draft for more thought. |
This is the more complete parameter validation pass that was out of scope for SDL3 release. I've currently set the default behavior of debug SDL builds to assert if parameter validation fails, and release builds to skip parameter validation entirely. We can adjust this as needed.
sdl2-compat will probably want to set hints for games that rely on parameter validation, or just always enable fast parameter validation.
This closes #13213