Added a single source of SDL object IDs

This ensures that we don't accidentally interpret an ID from one system as an ID in another system.
Audio device IDs are not covered here, since they have a unique numbering system.
This commit is contained in:
Sam Lantinga
2023-10-23 09:46:09 -07:00
parent e07f6c0a17
commit 38afd48daf
23 changed files with 37 additions and 50 deletions

View File

@@ -514,6 +514,20 @@ void SDL_Quit(void)
SDL_bInMainQuit = SDL_FALSE;
}
/* Assume we can wrap SDL_AtomicInt values and cast to Uint32 */
SDL_COMPILE_TIME_ASSERT(sizeof_object_id, sizeof(int) == sizeof(Uint32));
Uint32 SDL_GetNextObjectID(void)
{
static SDL_AtomicInt last_id;
Uint32 id = (Uint32)SDL_AtomicIncRef(&last_id) + 1;
if (id == 0) {
id = (Uint32)SDL_AtomicIncRef(&last_id) + 1;
}
return id;
}
/* Get the library version number */
int SDL_GetVersion(SDL_version *ver)
{