Fix SDL event initialization and backend context allocation#30
Fix SDL event initialization and backend context allocation#30kimkulling merged 2 commits intomainfrom
Conversation
- This initialization is based on an union and will cause undefined behavior.
WalkthroughSingle change in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/backends/sdl2_renderer.cpp`:
- Line 282: The line assigning ctx.mBackendCtx = new BackendContext;. has an
accidental trailing '.' after the semicolon which causes a compile error; edit
the assignment where ctx.mBackendCtx is set (new BackendContext) to remove the
extra '.' so the statement ends with just the semicolon and rebuild.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6897168-df2b-4695-8979-09776e8b2aa1
📒 Files selected for processing (1)
src/backends/sdl2_renderer.cpp
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/backends/sdl2_renderer.cpp (2)
504-504:⚠️ Potential issue | 🔴 CriticalSyntax error:
int32_t int sis invalid.This line has an erroneous
intkeyword that will cause a compilation failure on big-endian systems.🐛 Proposed fix
- const int32_t int s = (bytesPerPixel == 4) ? 0 : 8; + const int32_t s = (bytesPerPixel == 4) ? 0 : 8;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/backends/sdl2_renderer.cpp` at line 504, The line declaring s is malformed ("int32_t int s") causing a compile error; remove the stray "int" and declare s correctly as a single int32_t initialized from bytesPerPixel (e.g. replace the broken declaration in src/backends/sdl2_renderer.cpp with a single declaration of the symbol s using int32_t and the existing ternary using bytesPerPixel) so the variable s is properly defined on all platforms.
472-476:⚠️ Potential issue | 🟠 MajorBug: Accessing wrong union member for SDL_MOUSEMOTION events.
For
SDL_MOUSEMOTIONevents, the active union member isevent.motion, notevent.button. Accessingevent.button.x/yinstead ofevent.motion.x/yis technically undefined behavior (accessing inactive union member).🐛 Proposed fix
case SDL_MOUSEMOTION: { - const int32_t x = event.button.x; - const int32_t y = event.button.y; + const int32_t x = event.motion.x; + const int32_t y = event.motion.y; } break;Note: The variables
xandyare also currently unused. Consider either removing this case or implementing the mouse motion handling.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/backends/sdl2_renderer.cpp` around lines 472 - 476, The SDL_MOUSEMOTION case is reading the wrong union member (event.button) which is undefined; change accesses to use event.motion.x and event.motion.y in the SDL_MOUSEMOTION branch (or remove the unused x/y locals if motion handling is not needed). Locate the SDL_MOUSEMOTION switch case in sdl2_renderer.cpp and update the variables (or drop the case) so the active union member event.motion is used and unused variables are eliminated or used for actual mouse-move handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/backends/sdl2_renderer.cpp`:
- Line 504: The line declaring s is malformed ("int32_t int s") causing a
compile error; remove the stray "int" and declare s correctly as a single
int32_t initialized from bytesPerPixel (e.g. replace the broken declaration in
src/backends/sdl2_renderer.cpp with a single declaration of the symbol s using
int32_t and the existing ternary using bytesPerPixel) so the variable s is
properly defined on all platforms.
- Around line 472-476: The SDL_MOUSEMOTION case is reading the wrong union
member (event.button) which is undefined; change accesses to use event.motion.x
and event.motion.y in the SDL_MOUSEMOTION branch (or remove the unused x/y
locals if motion handling is not needed). Locate the SDL_MOUSEMOTION switch case
in sdl2_renderer.cpp and update the variables (or drop the case) so the active
union member event.motion is used and unused variables are eliminated or used
for actual mouse-move handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 21f1021d-929f-4d39-b122-590ac6ef162f
📒 Files selected for processing (1)
src/backends/sdl2_renderer.cpp



Summary by CodeRabbit