Skip to content

Commit 2009b82

Browse files
committed
utils: disable object validity check in release builds
1 parent 71f479b commit 2009b82

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Timeout multiplier to account
410410
set_option(SDL_EXAMPLES "Build the examples directory")
411411
dep_option(SDL_EXAMPLES_LINK_SHARED "link examples to shared SDL library" "${SDL_SHARED}" "SDL_SHARED;SDL_STATIC" "${SDL_SHARED}")
412412

413+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
414+
set(SDL_OBJECT_VALIDITY_CHECK_DEFAULT ON)
415+
else()
416+
set(SDL_OBJECT_VALIDITY_CHECK_DEFAULT OFF)
417+
endif()
418+
419+
set_option(SDL_OBJECT_VALIDITY_CHECK "Enable object validity check" ${SDL_OBJECT_VALIDITY_CHECK_DEFAULT})
420+
set(HAVE_OBJECT_VALIDITY_CHECK ${SDL_OBJECT_VALIDITY_CHECK})
421+
413422
if(VITA)
414423
set_option(VIDEO_VITA_PIB "Build with PSVita piglet gles2 support" OFF)
415424
set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF)

include/build_config/SDL_build_config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@
550550
#cmakedefine SDL_DISABLE_WINDOWS_IME 1
551551
#cmakedefine SDL_GDK_TEXTINPUT 1
552552

553+
/* Enable object validity check */
554+
#cmakedefine SDL_OBJECT_VALIDITY_CHECK
555+
553556
/* Platform specific definitions */
554557
#cmakedefine SDL_IPHONE_KEYBOARD 1
555558
#cmakedefine SDL_IPHONE_LAUNCHSCREEN 1

src/SDL_utils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static bool SDL_KeyMatchObject(void *unused, const void *a, const void *b)
150150

151151
void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
152152
{
153+
#ifdef SDL_OBJECT_VALIDITY_CHECK
153154
SDL_assert(object != NULL);
154155

155156
if (SDL_ShouldInit(&SDL_objects_init)) {
@@ -166,6 +167,7 @@ void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
166167
} else {
167168
SDL_RemoveFromHashTable(SDL_objects, object);
168169
}
170+
#endif
169171
}
170172

171173
bool SDL_ObjectValid(void *object, SDL_ObjectType type)
@@ -174,12 +176,15 @@ bool SDL_ObjectValid(void *object, SDL_ObjectType type)
174176
return false;
175177
}
176178

179+
#ifdef SDL_OBJECT_VALIDITY_CHECK
177180
const void *object_type;
178181
if (!SDL_FindInHashTable(SDL_objects, object, &object_type)) {
179182
return false;
180183
}
181-
182184
return (((SDL_ObjectType)(uintptr_t)object_type) == type);
185+
#else
186+
return true;
187+
#endif
183188
}
184189

185190
typedef struct GetOneObjectData

0 commit comments

Comments
 (0)