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
// 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.
#define OBJECT_VALIDATION_REQUIRED
#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (false)
#else
#define CHECK_PARAM(invalid) if (false)
#endif
#elif defined(SDL_ASSERT_INVALID_PARAMS)
#define OBJECT_VALIDATION_REQUIRED
#define CHECK_PARAM(invalid) SDL_assert_always(!(invalid)); if (invalid)
#else
#define CHECK_PARAM(invalid) if (invalid)

View File

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