Always enable object validation when checking is explicitly enabled

This commit is contained in:
Sam Lantinga
2025-10-01 13:53:19 -07:00
parent f66e4d0a43
commit 33c849d030
2 changed files with 6 additions and 1 deletions

View File

@@ -291,11 +291,13 @@ extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
// If you define SDL_DISABLE_INVALID_PARAMS, you're promising that you'll // If you define SDL_DISABLE_INVALID_PARAMS, you're promising that you'll
// never pass an invalid parameter to SDL, since it may crash or lead to // never pass an invalid parameter to SDL, since it may crash or lead to
// hard to diagnose bugs. Let's assert that this is true in debug builds. // hard to diagnose bugs. Let's assert that this is true in debug builds.
#define OBJECT_VALIDATION_REQUIRED
#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (false) #define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (false)
#else #else
#define CHECK_PARAM(invalid) if (false) #define CHECK_PARAM(invalid) if (false)
#endif #endif
#elif defined(SDL_ASSERT_INVALID_PARAMS) #elif defined(SDL_ASSERT_INVALID_PARAMS)
#define OBJECT_VALIDATION_REQUIRED
#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (invalid) #define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (invalid)
#else #else
#define CHECK_PARAM(invalid) if (invalid) #define CHECK_PARAM(invalid) if (invalid)

View File

@@ -137,12 +137,13 @@ Uint32 SDL_GetNextObjectID(void)
static SDL_InitState SDL_objects_init; static SDL_InitState SDL_objects_init;
static SDL_HashTable *SDL_objects; static SDL_HashTable *SDL_objects;
bool SDL_object_validation = false; bool SDL_object_validation = true;
static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *name, const char *oldValue, const char *hint) static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{ {
bool validation_enabled = true; bool validation_enabled = true;
#ifndef OBJECT_VALIDATION_REQUIRED
if (hint) { if (hint) {
switch (*hint) { switch (*hint) {
case '0': case '0':
@@ -156,6 +157,8 @@ static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *na
break; break;
} }
} }
#endif // !OBJECT_VALIDATION_REQUIRED
SDL_object_validation = validation_enabled; SDL_object_validation = validation_enabled;
} }