X Tutup
Skip to content

Fix custom cursor flickering in web builds#103304

Closed
Chubercik wants to merge 1 commit intogodotengine:masterfrom
Chubercik:fix_custom_cursor
Closed

Fix custom cursor flickering in web builds#103304
Chubercik wants to merge 1 commit intogodotengine:masterfrom
Chubercik:fix_custom_cursor

Conversation

@Chubercik
Copy link
Contributor

Fixes #102403.

Implement caching of the custom cursor state in DisplayServerWeb to prevent redundant updates to the browser's cursor. This change computes a hash based on the cursor resource, shape, and hotspot, and only updates the browser's cursor when the hash changes. This mitigates the flickering observed in web exports when set_custom_mouse_cursor() is called every frame.

@Chubercik Chubercik requested a review from a team as a code owner February 25, 2025 23:10
@AThousandShips AThousandShips added bug platform:web cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:platforms topic:gui labels Feb 26, 2025
@AThousandShips AThousandShips added this to the 4.5 milestone Feb 26, 2025
@Chubercik
Copy link
Contributor Author

I tested the issue's project with this PR, and the flickering is gone. Everything else works as expected (changing the cursor upon left click, switching back to the previous one upon release).

I'm not 100% sure about the hashing, that is, whether we should worry about potential hash collisions. If anyone more experienced than me would like to weigh in on this, it would be greatly appreciated.

@Chubercik
Copy link
Contributor Author

BTW, this fixes the issue at hand (flickering when repeatedly changing the cursor to the same graphic), but I can imagine flickering would still be present if someone wanted to have an animated cursor by cycling through different graphics.

Not a roadblock for this PR to be merged, but a more robust solution, if possible, would be nice.

Implement caching of the custom cursor state in `DisplayServerWeb` to prevent redundant updates to the browser's cursor. This change computes a hash based on the cursor resource, shape, and hotspot, and only updates the browser's cursor when the hash changes. This mitigates the flickering observed in web exports when `set_custom_mouse_cursor()` is called every frame.
@Chubercik Chubercik force-pushed the fix_custom_cursor branch from a60e7f3 to df9d47f Compare June 7, 2025 09:13
@Chubercik
Copy link
Contributor Author

Rebased 🔛🔝

@brane-games
Copy link

Hey, is there any way to speed up merging of this fix?

Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's the way to go. Implementing an hashing function just to cache a value such as setting a custom image for a cursor seems way overkill. And especially since the behavior would differ from every other platform.

(Edit: Implementing an hashing function the way it is currently done. I also thought implementing hashing, but the current API is ambiguous. What happens if we pass the same reference, but the actual data of the reference changed? Does it get cached? Currently, there's no caching on other platforms, and I don't see how we can implement a caching system on just a platform, especially since it there would be no way to bust the cache.)

The fix, IMHO, would be just to not update the cursor each frame. That's a limitation of the platform. See #102403 (comment) for an example of how to do it.

@Repiteo Repiteo modified the milestones: 4.5, 4.x Sep 18, 2025
@Repiteo Repiteo added the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Sep 18, 2025
@akien-mga akien-mga removed cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Jan 8, 2026
@akien-mga
Copy link
Member

Superseded by #107586 (for now).

@akien-mga akien-mga closed this Jan 13, 2026
@akien-mga akien-mga added archived and removed cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Jan 13, 2026
@akien-mga akien-mga removed this from the 4.x milestone Jan 13, 2026
@Chubercik Chubercik deleted the fix_custom_cursor branch January 13, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom mouse cursor flickers in web build

6 participants

X Tutup