tray: improved error checking

Also clean up any existing trays when the program quits

Fixes https://github.com/libsdl-org/SDL/issues/11893
This commit is contained in:
Sam Lantinga
2025-01-19 09:59:12 -08:00
parent b716eeefef
commit 7570ab106d
9 changed files with 334 additions and 83 deletions

View File

@@ -178,6 +178,22 @@ bool SDL_ObjectValid(void *object, SDL_ObjectType type)
return (((SDL_ObjectType)(uintptr_t)object_type) == type);
}
int SDL_GetObjects(SDL_ObjectType type, void **objects, int count)
{
const void *object, *object_type;
void *iter = NULL;
int num_objects = 0;
while (SDL_IterateHashTable(SDL_objects, &object, &object_type, &iter)) {
if ((SDL_ObjectType)(uintptr_t)object_type == type) {
if (num_objects < count) {
objects[num_objects] = (void *)object;
}
++num_objects;
}
}
return num_objects;
}
void SDL_SetObjectsInvalid(void)
{
if (SDL_ShouldQuit(&SDL_objects_init)) {
@@ -217,6 +233,9 @@ void SDL_SetObjectsInvalid(void)
case SDL_OBJECT_TYPE_THREAD:
type = "thread";
break;
case SDL_OBJECT_TYPE_TRAY:
type = "SDL_Tray";
break;
default:
type = "unknown object";
break;