Просмотр исходного кода

events: Update self-referential pointers when copying event objects

Pointers to static internal data need to be updated when copying events, or the cleanup code will attempt to free old stack data that went out of scope.
Frank Praznik 1 год назад
Родитель
Сommit
52c4e3eab3
1 измененных файлов с 14 добавлено и 2 удалено
  1. 14 2
      src/events/SDL_events.c

+ 14 - 2
src/events/SDL_events.c

@@ -468,6 +468,18 @@ static void SDL_LogEvent(const SDL_Event *event)
 #undef uint
 #undef uint
 }
 }
 
 
+static void SDL_CopyEvent(SDL_Event *dst, SDL_Event *src)
+{
+    *dst = *src;
+
+    /* Pointers to internal static data must be updated when copying. */
+    if (src->type == SDL_EVENT_TEXT_EDITING && src->edit.text == src->edit.short_text) {
+        dst->edit.text = dst->edit.short_text;
+    } else if (src->type == SDL_EVENT_DROP_TEXT && src->drop.data == src->drop.short_data) {
+        dst->drop.data = dst->drop.short_data;
+    }
+}
+
 /* Public functions */
 /* Public functions */
 
 
 void SDL_StopEventLoop(void)
 void SDL_StopEventLoop(void)
@@ -597,7 +609,7 @@ static int SDL_AddEvent(SDL_Event *event)
         SDL_LogEvent(event);
         SDL_LogEvent(event);
     }
     }
 
 
-    entry->event = *event;
+    SDL_CopyEvent(&entry->event, event);
     if (event->type == SDL_EVENT_POLL_SENTINEL) {
     if (event->type == SDL_EVENT_POLL_SENTINEL) {
         SDL_AtomicAdd(&SDL_sentinel_pending, 1);
         SDL_AtomicAdd(&SDL_sentinel_pending, 1);
     }
     }
@@ -706,7 +718,7 @@ static int SDL_PeepEventsInternal(SDL_Event *events, int numevents, SDL_eventact
                 type = entry->event.type;
                 type = entry->event.type;
                 if (minType <= type && type <= maxType) {
                 if (minType <= type && type <= maxType) {
                     if (events) {
                     if (events) {
-                        events[used] = entry->event;
+                        SDL_CopyEvent(&events[used], &entry->event);
 
 
                         if (action == SDL_GETEVENT) {
                         if (action == SDL_GETEVENT) {
                             SDL_CutEvent(entry);
                             SDL_CutEvent(entry);