mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 20:08:13 +00:00
SDL_ResetHint() no longer clears the callbacks associated with a hint
Also added SDL_ResetHints() to reset all callbacks, and clarified that SDL_ClearHints() is just used for cleanup at shutdown. Fixes https://github.com/libsdl-org/SDL/issues/6313
This commit is contained in:
@@ -100,7 +100,6 @@ SDL_bool
|
||||
SDL_ResetHint(const char *name)
|
||||
{
|
||||
const char *env;
|
||||
SDL_Hint *hint, *prev;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
if (!name) {
|
||||
@@ -108,7 +107,7 @@ SDL_ResetHint(const char *name)
|
||||
}
|
||||
|
||||
env = SDL_getenv(name);
|
||||
for (prev = NULL, hint = SDL_hints; hint; prev = hint, hint = hint->next) {
|
||||
for (hint = SDL_hints; hint; hint = hint->next) {
|
||||
if (SDL_strcmp(name, hint->name) == 0) {
|
||||
if ((env == NULL && hint->value != NULL) ||
|
||||
(env != NULL && hint->value == NULL) ||
|
||||
@@ -120,19 +119,39 @@ SDL_ResetHint(const char *name)
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
if (prev) {
|
||||
prev->next = hint->next;
|
||||
} else {
|
||||
SDL_hints = hint->next;
|
||||
}
|
||||
SDL_free(hint->value);
|
||||
SDL_free(hint);
|
||||
hint->value = NULL;
|
||||
hint->priority = SDL_HINT_DEFAULT;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_ResetHints(void)
|
||||
{
|
||||
const char *env;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
for (hint = SDL_hints; hint; hint = hint->next) {
|
||||
env = SDL_getenv(hint->name);
|
||||
if ((env == NULL && hint->value != NULL) ||
|
||||
(env != NULL && hint->value == NULL) ||
|
||||
(env && SDL_strcmp(env, hint->value) != 0)) {
|
||||
for (entry = hint->callbacks; entry; ) {
|
||||
/* Save the next entry in case this one is deleted */
|
||||
SDL_HintWatch *next = entry->next;
|
||||
entry->callback(entry->userdata, name, hint->value, env);
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
SDL_free(hint->value);
|
||||
hint->value = NULL;
|
||||
hint->priority = SDL_HINT_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_SetHint(const char *name, const char *value)
|
||||
{
|
||||
|
Reference in New Issue
Block a user