Skip to content

Commit f6f4664

Browse files
committed
Fixed rare cursor corruption on Windows
If the cursor was created with a temporary surface that was pointing at external memory, then when the cursor is used it might be referencing memory that had already been freed.
1 parent 93a5d33 commit f6f4664

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/video/windows/SDL_windowsmouse.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,23 @@ static SDL_Cursor *WIN_CreateAnimatedCursorAndData(SDL_CursorFrameInfo *frames,
148148
data->hot_y = hot_y;
149149
data->num_frames = frame_count;
150150
for (int i = 0; i < frame_count; ++i) {
151-
data->frames[i].surface = frames[i].surface;
151+
SDL_Surface *surface = frames[i].surface;
152+
if (surface->flags & SDL_SURFACE_PREALLOCATED) {
153+
surface = SDL_DuplicateSurface(surface);
154+
if (!surface) {
155+
while (i > 0) {
156+
--i;
157+
SDL_DestroySurface(data->frames[i].surface);
158+
}
159+
SDL_free(data);
160+
SDL_free(cursor);
161+
return NULL;
162+
}
163+
} else {
164+
++surface->refcount;
165+
}
166+
data->frames[i].surface = surface;
152167
data->frames[i].duration = frames[i].duration;
153-
++frames[i].surface->refcount;
154168
}
155169
cursor->internal = data;
156170
return cursor;

0 commit comments

Comments
 (0)