Skip to content

[rcore][web]Fix: Inaccurate mouse position in raylib WASM on web pages #5019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ProtossGenius
Copy link

Fixed an issue where the mouse position was inaccurate when the raylib library was compiled to WASM for web pages.

Problem Cause:
Upon investigation, the issue was determined to be caused by glfwSetCursorPosCallback (which is emulated in the WASM environment) returning the mouse position relative to the initial canvas size created during the InitWindow call. This means that even if the canvas element's size on the web page changed (e.g., after a window resize via CSS or JavaScript), glfwSetCursorPosCallback would still report mouse positions based on the original, fixed canvas dimensions. This led to incorrect mouse coordinates calculated by raylib's internals when the web page was not full-screen or when the Canvas element's size was dynamic.

Fixed an issue where the mouse position was inaccurate when the raylib library was compiled to WASM for web pages.

Problem Cause:
Upon investigation, the issue was determined to be caused by glfwSetCursorPosCallback (which is emulated in the WASM environment) returning the mouse position relative to the initial canvas size created during the InitWindow call. This means that even if the canvas element's size on the web page changed (e.g., after a window resize via CSS or JavaScript), glfwSetCursorPosCallback would still report mouse positions based on the original, fixed canvas dimensions. This led to incorrect mouse coordinates calculated by raylib's internals when the web page was not full-screen or when the Canvas element's size was dynamic.
@ProtossGenius ProtossGenius changed the title Fix: Inaccurate mouse position in raylib WASM on web pages [rcore][web]Fix: Inaccurate mouse position in raylib WASM on web pages Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant