[rcore][SDL] Relative mouse motion is overwritten in event loop
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
Research direction
Start in src/platforms/rcore_desktop_sdl.c at the SDL_PollEvent loop around the linked lines, then trace how GetMouseDelta is consumed by the core_3d_camera_free.c example. Reproduce with the provided cursor-disabled example at capped and unlimited FPS; done means relative motion behaves consistently under the SDL backend.
Written by the indexing model from the issue text.
Description
Please, before submitting a new issue verify and check:
- I tested it on latest raylib version from master branch
- I checked there is no similar issue already reported
- I checked the documentation on the wiki
- My code has no errors or misuse of raylib
Issue description
Relative mouse motion is frame-rate dependent when using the SDL backend with the cursor disabled. I noticed this after switching to SDL from the GLFW backend in my fps game project. It turns out that raylib overwrites relative mouse motion with the last SDL_MOUSEMOTION event in while (SDL_PollEvent(&event) != 0) loop. It should accumulate xrel and yrel instead. I can submit a PR with the fix.
Environment
- PLATFORM_DESKTOP_SDL
- GRAPHICS_API_OPENGL_33
- Windows 11 Pro
- MSVC 19.51.36257 for x64
Issue Screenshot
If possible, provide a screenshot that illustrates the issue. Usually an image is better than a thousand words.
Code Example
Provide minimal reproduction code to test the issue. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced issue.
Any code that uses Vector2 GetMouseDelta(void); function with the cursor disabled.
Below is a slightly modified core_3d_camera_free.c example which allows toggling FPS on and off to reproduce the issue.
#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
// Define the camera to look into our 3d world
Camera3D camera = { 0 };
camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
DisableCursor(); // Limit cursor to relative movement inside the window
int targetFPS = 60;
SetTargetFPS(targetFPS);
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
if (IsKeyPressed(KEY_SPACE))
{
if (targetFPS == 0) targetFPS = 60;
else targetFPS = 0;
SetTargetFPS(targetFPS);
}
UpdateCamera(&camera, CAMERA_FREE);
if (IsKeyPressed(KEY_Z)) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
DrawGrid(10, 1.0f);
EndMode3D();
DrawFPS(10, 10);
DrawText("- Z to zoom to (0, 0, 0)", 40, 80, 10, DARKGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
In PLATFORM_DESKTOP_SDL camera rotation slows down when FPS is capped but works normally with unlimited FPS, unlike PLATFORM_DESKTOP_GLFW where it works fine in both cases.
- Dominant language
- C
- Stars
- 34.8k
- Forks
- 3.3k
- Avg merge
- 17h 56m
- Merged PRs (30d)
- 59
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from raysan5/raylib
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
windowing
Difficulty 4/5 3-5 days Newbie friendliness 50/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
[rcore][drm] Link failure for `eglGetPlatformDisplay()` on Mali GPUs with stripped EGL symbol tables Openplatform: DRM/RPI
Difficulty 4/5 3-5 days Newbie friendliness 54/100
-
examples
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100