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:
Sam Lantinga
2022-10-02 17:17:31 -07:00
parent 19ecb64e0d
commit 64ea6cefaf
6 changed files with 99 additions and 9 deletions

View File

@@ -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)
{

View File

@@ -865,3 +865,4 @@
++'_SDL_HasPrimarySelectionText'.'SDL2.dll'.'SDL_HasPrimarySelectionText'
++'_SDL_GameControllerGetSensorDataWithTimestamp'.'SDL2.dll'.'SDL_GameControllerGetSensorDataWithTimestamp'
++'_SDL_SensorGetDataWithTimestamp'.'SDL2.dll'.'SDL_SensorGetDataWithTimestamp'
++'_SDL_ResetHints'.'SDL2.dll'.'SDL_ResetHints'

View File

@@ -891,3 +891,4 @@
#define SDL_HasPrimarySelectionText SDL_HasPrimarySelectionText_REAL
#define SDL_GameControllerGetSensorDataWithTimestamp SDL_GameControllerGetSensorDataWithTimestamp_REAL
#define SDL_SensorGetDataWithTimestamp SDL_SensorGetDataWithTimestamp_REAL
#define SDL_ResetHints SDL_ResetHints_REAL

View File

@@ -974,3 +974,4 @@ SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HasPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_GameControllerGetSensorDataWithTimestamp,(SDL_GameController *a, SDL_SensorType b, Uint64 *c, float *d, int e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_SensorGetDataWithTimestamp,(SDL_Sensor *a, Uint64 *b, float *c, int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(void,SDL_ResetHints,(void),(),)