Skip to content

Conversation

ankith26
Copy link
Member

A random collection of bugfixes. Some of these bugs were introduced fairly recently by me during the SDL3 porting, good thing they didn't make it to a release. These bugs were caught by coderabbit.

@ankith26 ankith26 requested a review from a team as a code owner September 22, 2025 13:02
Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

📝 Walkthrough

Walkthrough

Updates adjust control-flow conditions across display and window handling, correct RGB channel loss/shift in 32bpp packing, and fix surface lock/unlock logic. No public API signatures changed. Warnings on OS-forced resize are triggered on size mismatch only.

Changes

Cohort / File(s) Summary
SDL3 windowing/control flow adjustments
src_c/display.c, src_c/window.c
display.c: In SDL3 path, pg_ResizeEventWatch now early-returns when event type is outside SDL window event range; pg_set_mode warns on any size mismatch. window.c: window_set_modal_for treats negative return as error; non-negative as success.
Pixel packing correctness (32bpp RGB)
src_c/image.c
Corrects per-channel loss application: uses Gloss for G and Bloss for B when packing 32bpp RGB, leaving R and alpha behavior unchanged.
Surface lock/unlock control
src_c/pixelarray_methods.c
In _make_surface, lock/unlock now occurs only when SDL_MUSTLOCK(new_surf) is true; previously inverted.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant SDL as SDL Event Loop
  participant EV as pg_ResizeEventWatch (SDL3)
  participant DISP as display.c handlers

  SDL->>EV: SDL_Event e
  alt e.type NOT in SDL_WINDOW_EVENT range
    EV-->>SDL: return 0 (no processing)
  else e.type in window event range
    EV->>DISP: handle window event
    DISP-->>EV: processed
    EV-->>SDL: return 1
  end
  note over EV,DISP: Condition inverted to early-return on non-window events
Loading
sequenceDiagram
  autonumber
  participant PA as _make_surface
  participant S as SDL_Surface

  PA->>S: SDL_MUSTLOCK(S)?
  alt Must lock == true
    PA->>S: SDL_LockSurface(S)
    PA->>S: ... write pixels ...
    PA->>S: SDL_UnlockSurface(S)
  else Must lock == false
    PA->>S: ... write pixels without lock ...
  end
  note over PA,S: Lock/unlock performed only when required
Loading
sequenceDiagram
  autonumber
  participant API as window_set_modal_for
  participant CORE as PG_SetWindowModalFor

  API->>CORE: set modal relationship
  CORE-->>API: int rc
  alt rc < 0
    API-->>API: treat as error
  else rc >= 0
    API-->>API: success path
  end
  note over API: Error condition changed to (rc < 0)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

display, sdl3

Suggested reviewers

  • Starbuck5
  • MyreMylar

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title accurately indicates this PR is a collection of bug fixes and explicitly lists the affected areas (display, window, image, pixelarray), which matches the provided raw_summary and PR objectives describing fixes across those files; while it uses the word "Misc," the parenthetical scope makes the intent clear and relevant to the changeset.
Description Check ✅ Passed The PR description plainly states this is a collection of bug fixes introduced during the SDL3 porting and credits coderabbit for finding them, which is directly related to the changes summarized in the raw_summary and PR objectives and therefore not off-topic.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ankith26-misc-fixes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src_c/display.c (1)

1687-1695: SDL3 vsync check is inverted — triggers error when vsync is actually enabled

SDL_GetRenderVSync(pg_renderer, &has_vsync) sets has_vsync non‑zero when vsync is ON. The code errors when vsync && has_vsync, which is backwards. It should error when vsync was requested but is NOT enabled.

Apply:

-                    if (vsync && has_vsync) {
+                    if (vsync && !has_vsync) {
                         PyErr_SetString(pgExc_SDLError,
                                         "could not enable vsync");
                         _display_state_cleanup(state);
                         goto DESTROY_WINDOW;
                     }
🧹 Nitpick comments (1)
src_c/pixelarray_methods.c (1)

161-164: Lock only when required: inversion fix is correct

Lock/unlock now guard on SDL_MUSTLOCK(new_surf); that’s the right behavior.

Consider checking the return value of SDL_LockSurface(new_surf) and raising on failure to avoid copying into an unlocked surface on error.

Also applies to: 240-242

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93189e3 and b438502.

📒 Files selected for processing (4)
  • src_c/display.c (2 hunks)
  • src_c/image.c (1 hunks)
  • src_c/pixelarray_methods.c (2 hunks)
  • src_c/window.c (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-01T20:18:57.500Z
Learnt from: Starbuck5
PR: pygame-community/pygame-ce#3573
File: src_c/_pygame.h:108-133
Timestamp: 2025-09-01T20:18:57.500Z
Learning: In pygame-ce PR #3573, PG_SURF_BitsPerPixel was changed from a simple macro to a static inline function to handle SDL2/SDL3 differences. SDL2's BitsPerPixel includes padding bits (e.g., RGBX => 32) while SDL3's SDL_BITSPERPIXEL excludes padding (e.g., RGBX => 24). The new implementation bridges this gap rather than removing the helper entirely.

Applied to files:

  • src_c/display.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: x86_64
  • GitHub Check: arm64
  • GitHub Check: i686
  • GitHub Check: aarch64
  • GitHub Check: x86_64
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: debug_coverage (ubuntu-24.04, 3.13.5)
  • GitHub Check: debug_coverage (ubuntu-24.04, 3.9.23)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: msys2 (clang64, clang-x86_64)
  • GitHub Check: Debian (Bookworm - 12) [s390x]
  • GitHub Check: msys2 (ucrt64, ucrt-x86_64)
  • GitHub Check: AMD64
  • GitHub Check: Debian (Bookworm - 12) [armv6]
  • GitHub Check: Debian (Bookworm - 12) [ppc64le]
  • GitHub Check: msys2 (mingw64, x86_64)
  • GitHub Check: Debian (Bookworm - 12) [armv7]
  • GitHub Check: x86
  • GitHub Check: dev-check
🔇 Additional comments (4)
src_c/image.c (1)

701-703: Fix G/B channel loss application in 32bpp RGB path

Using Gloss and Bloss (not Rloss) for data[1] and data[2] is correct. Approving.

Please add/adjust a unit test that exercises 32bpp RGB surfaces and verifies green/blue bytes match the format masks/shift/loss.

src_c/display.c (2)

897-901: Event watch early‑return condition is now correct

Inverting the check to return early on non‑window events is right and avoids extra branching.


1832-1846: Resize warning gate: width/height mismatch check is fine

The simplified mismatch check is reasonable under the existing gating. Approved.

src_c/window.c (1)

476-478: Correct return-code check for PG_SetWindowModalFor — verified

Switching to "< 0" correctly treats negative as error (SDL3-style). The provided rg output shows only the call at src_c/window.c:476–478 and no other call sites use truthiness checks.

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