Skip to content

Fullscreen - #28

Merged
rene merged 3 commits into
mainfrom
fullscreen
Oct 17, 2026
Merged

rene merged 3 commits into
mainfrom
fullscreen

Conversation

@rene

@rene rene commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Full screen mode

@rene

rene commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@claude

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @rene's task —— View job


Code Review

  • Gather context
  • Read changed files and analyze
  • Post review findings

Findings

Bug — src/gui/sdl/gui.c, scale regression (introduced in this PR)

// diff lines ~198-201
if (scale <= 0) {
    rnes_gui.width = SCREEN_WIDTH;
    rnes_gui.height = SCREEN_HEIGHT;
-   rnes_gui.scale = 1;         // ← original
+   rnes_gui.scale = scale;     // ← stores 0 or a negative value

The original code correctly stored 1 as the effective scale when the caller passed 0. The new code stores the raw (invalid) value instead. Any caller that later reads gui_get_scale() — including gui_set_scale() multiplications — will see 0 or a negative integer. This is a straightforward regression; restore rnes_gui.scale = 1;.


Bug — src/gui/sdl/gui.c, NULL renderer passed to SDL_RenderSetLogicalSize

// gui_init, after SDL_CreateRenderer
rnes_gui.renderer =
    SDL_CreateRenderer(rnes_gui.win, -1, SDL_RENDERER_ACCELERATED);
/* Keep the aspect ratio and letterbox in fullscreen */
SDL_RenderSetLogicalSize(rnes_gui.renderer, ...);   // renderer may be NULL here

SDL_CreateRenderer can return NULL (e.g. no hardware acceleration). The NULL check for rnes_gui.renderer happens after SDL_RenderSetLogicalSize is already called with a potentially NULL pointer. SDL itself handles a NULL renderer gracefully in most builds, but it is undefined behaviour in C and should be fixed — move the NULL check before calling SDL_RenderSetLogicalSize, or fall back to SDL_RENDERER_SOFTWARE.


Bug — src/gui/sdl/gui.c, missing sem_post on init failure after adding fullscreen call

// gui_init bottom, lines ~228-237
if (rnes_gui.texture == NULL || rnes_gui.renderer == NULL ||
    rnes_gui.text_texture == NULL) {
    SDL_PauseAudio(1);
    TTF_Quit();
    SDL_Quit();
    // ← no return -1 here already, but now gui_set_fullscreen is called
    //   unconditionally below even on this error path
}
SDL_SetTextureBlendMode(rnes_gui.text_texture, SDL_BLENDMODE_BLEND);

/* Check/set full screen mode */
gui_set_fullscreen(rnes_gui.fullscreen);   // called even when renderer is NULL

gui_set_fullscreen calls SDL_SetWindowFullscreen(rnes_gui.win, ...). If the error branch above was hit, rnes_gui.win might also be NULL (depending on which allocation failed). There is a pre-existing missing return -1 in the error block; this PR makes it worse by adding another SDL call after it. The fix is to add return -1; to that error block (pre-existing issue, but the PR touches this exact area).


Stale docstring — src/interface/posix/rNES.c, gui_th_loop

/**
 * GUI emulation thread (main routine)
 * @param args Pointer to an integer variable with scale factor   ← stale
 */
static void *gui_th_loop(void *args)
{
    struct _gui_args *gargs = (struct _gui_args *)args;

The @param doc still says "integer variable with scale factor" but args is now a struct _gui_args *. Minor, but the docs for this function were updated in docs/thread-model.md — the in-source comment should match.


Minor — src/gui/sdl/gui.c, F12 handler: redundant type check inside switch

case SDLK_F12:
    if (main_ev.type == SDL_KEYDOWN && !main_ev.key.repeat) {

The outer switch already dispatches only SDL_KEYDOWN / SDL_KEYUP events (look at the surrounding code). Re-checking main_ev.type == SDL_KEYDOWN inside the case is harmless but redundant. The !main_ev.key.repeat guard is correct and sufficient. Other keys (Q, arrow keys, etc.) don't have this inner type check — for consistency, remove it or apply the same pattern elsewhere.


Summary

Severity File Issue
Bug src/gui/sdl/gui.c:201 rnes_gui.scale set to 0/negative instead of 1 for default scale
Bug src/gui/sdl/gui.c:216 SDL_RenderSetLogicalSize called before NULL check on renderer
Bug src/gui/sdl/gui.c:237 gui_set_fullscreen called on error path where win/renderer may be NULL
Minor src/interface/posix/rNES.c:308 Stale @param docstring for gui_th_loop
Nit src/gui/sdl/gui.c:334 Redundant SDL_KEYDOWN type check inside the F12 case

The fullscreen logic itself (SDL_WINDOW_FULLSCREEN_DESKTOP + SDL_RenderSetLogicalSize for letterboxing, cursor hiding, F12 toggle, struct _gui_args refactor) is well-structured. The scale regression in the scale <= 0 branch is the most important fix needed before merging.

@rene
rene force-pushed the fullscreen branch 2 times, most recently from c397da8 to b95b9e5 Compare October 17, 2026 14:47
@rene

rene commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@claude

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @rene's task —— View job


Code Review

  • Gather context — read changed files
  • Analyze diff for bugs/issues
  • Post inline review comments

Note: I don't have permission to post inline review comments via the GitHub review API in this environment. Posting findings as a comment instead.


Findings

Bug — src/gui/sdl/gui.c:216 — NULL renderer passed to SDL_RenderSetLogicalSize

/* Create Hardware Accelerated Renderer */
rnes_gui.renderer =
    SDL_CreateRenderer(rnes_gui.win, -1, SDL_RENDERER_ACCELERATED);
/* Keep the aspect ratio and letterbox in fullscreen */
SDL_RenderSetLogicalSize(rnes_gui.renderer, rnes_gui.width,   // ← renderer may be NULL
                         rnes_gui.height);

SDL_CreateRenderer returns NULL if hardware acceleration is unavailable. The NULL check on rnes_gui.renderer happens at line 229, after this call. Passing NULL here is undefined behaviour in C. Fix: move the NULL check before this line, or fall back to SDL_RENDERER_SOFTWARE:

rnes_gui.renderer =
    SDL_CreateRenderer(rnes_gui.win, -1, SDL_RENDERER_ACCELERATED);
if (rnes_gui.renderer == NULL) {
    rnes_gui.renderer =
        SDL_CreateRenderer(rnes_gui.win, -1, SDL_RENDERER_SOFTWARE);
}
if (rnes_gui.renderer != NULL) {
    SDL_RenderSetLogicalSize(rnes_gui.renderer, rnes_gui.width, rnes_gui.height);
}

Bug — src/gui/sdl/gui.c:239 — gui_set_fullscreen called after error path

if (rnes_gui.texture == NULL || rnes_gui.renderer == NULL ||
    rnes_gui.text_texture == NULL) {
    SDL_PauseAudio(1);
    TTF_Quit();
    SDL_Quit();
    return -1;            // ← good, this was added in the PR
}
SDL_SetTextureBlendMode(rnes_gui.text_texture, SDL_BLENDMODE_BLEND);

/* Check/set full screen mode */
gui_set_fullscreen(rnes_gui.fullscreen);   // ← reached only on success path now

The PR added the missing return -1 — so gui_set_fullscreen is now only reached on the success path. This is fine as-is. ✓


Nit — src/gui/sdl/gui.c:336 — redundant SDL_KEYDOWN type check inside SDLK_F12 case

case SDLK_F12:
    /* Toggle fullscreen mode */
    if (main_ev.type == SDL_KEYDOWN && !main_ev.key.repeat) {

The enclosing else if at line 299 already gates on SDL_KEYDOWN || SDL_KEYUP. The inner main_ev.type == SDL_KEYDOWN check is redundant — key_state already encodes this information. The !main_ev.key.repeat guard is correct. Other keys don't have this extra check; for consistency, simplify to:

case SDLK_F12:
    if (key_state == KEY_PRESSED && !main_ev.key.repeat) {

Nit — src/gui/sdl/gui.c:440 — gui_set_fullscreen stores fullscreen unconditionally on success

int gui_set_fullscreen(uint8_t fullscreen)
{
    ...
    if (SDL_SetWindowFullscreen(rnes_gui.win, flags) < 0) {
        log_err("Cannot change fullscreen mode: %s\n", SDL_GetError());
        return -1;
    }
    SDL_ShowCursor(cursor);

    rnes_gui.fullscreen = fullscreen;   // ← only reached on success, correct
    return 0;
}

State is only updated on success — this is correct. ✓


Summary

Severity Location Issue
Bug src/gui/sdl/gui.c:216 SDL_RenderSetLogicalSize called before NULL-checking the renderer
Nit src/gui/sdl/gui.c:336 Redundant SDL_KEYDOWN type check inside SDLK_F12 case

The overall fullscreen implementation is clean. The struct _gui_args refactor, SDL_WINDOW_FULLSCREEN_DESKTOP + SDL_RenderSetLogicalSize for letterboxing, cursor hiding, and F12 toggle are all well-structured. The previously reported scale regression (rnes_gui.scale = scale storing 0) and missing return -1 have already been fixed in the current diff — the code correctly stores 1 and returns early on error. The one actionable bug remaining is the NULL renderer being passed to SDL_RenderSetLogicalSize before the NULL check.

rene added 3 commits October 17, 2026 16:55
- Add -f / --fullscreen argument
- Use F12 to toggle fullscreen mode during runtime

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
Update documentation about the full screen mode.

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
Handle the new fullscreen parameter.

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
@rene
rene merged commit 9c87035 into main Oct 17, 2026
4 checks passed
@rene
rene deleted the fullscreen branch October 17, 2026 15:01
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