Commit af5efadd9fd8b26d075c92a57df40428846b234e

Sean Ridenour 2023-02-04T10:29:59

Setting the same mouse cursor twice is a no-op This fixes extremely poor event polling performance on MacOS when using Dear ImGui, which sets the mouse cursor every frame.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 3cd82b6..a359c8e 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -1333,6 +1333,11 @@ void SDL_SetCursor(SDL_Cursor *cursor)
 {
     SDL_Mouse *mouse = SDL_GetMouse();
 
+    /* Return immediately if setting the cursor to the currently set one (fixes #7151) */
+    if (cursor == mouse->cur_cursor) {
+        return;
+    }
+
     /* Set the new cursor */
     if (cursor) {
         /* Make sure the cursor is still valid for this mouse */