libretro / libretro/RetroArch

Error saving screenshots on macOS

Open
#17,186 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

platform: osx
Dominant language
C
Stars
14.1k
Forks
2.2k
Avg merge
7h 35m
Merged PRs (30d)
51

Description

Description

On a macOS (15.0.1, arm64), building from Xcode, I am getting an error (on screen) whenever trying to save screenshots.

Expected behavior

Expected the screenshot to be saved to a PNG file successfully.

Actual behavior

I occasionally get an error and the screenshot isn't saved.

Steps to reproduce the bug
  1. Open Retroarch
  2. Open a GBA rom
  3. Open mGBA
  4. Click Command -> Take Screenshot
  5. See the error pop up
Bisect Results

I don't know what this means, but I was messing with the code anyway, so here's what I found.

While investigating the error I added a few printf's to debug it, and after that a few screenshots were successfully saved in weirdly named directories:

'/Users/vini/Library/Containers/com.libretro.dist.RetroArch/Data/`64o/Pokemon - LeafGreen Version (USA, Europe) (Rev 1)-241115-151226.png'
'/Users/vini/Library/Containers/com.libretro.dist.RetroArch/Data/`v]o/Pokemon - LeafGreen Version (USA, Europe) (Rev 1)-241115-150716.png'
'/Users/vini/Library/Containers/com.libretro.dist.RetroArch/Data/`vqo/Pokemon - LeafGreen Version (USA, Europe) (Rev 1)-241115-150345.png'

Looking at the code, what seems to be happening is:

  • screenshot_dump gets called (line 255) with the following arguments:
    • screenshot_dir: ""
    • name_base: /Applications/_Games/Pokemon - LeafGreen Version (USA, Europe) (Rev 1)
    • savestate: 0
    • has_valid_framebuffer: 0
    • fullpath: 0
    • use_thread: 1
  • new_screenshot_dir is declared (line 318) but never initialized (so it contains memory trash, I suppose?)
  • settings->bools.auto_screenshot_filename is true, so we calculate a new state->shotname (e.g. Pokemon - LeafGreen Version (USA, Europe) (Rev 1)-241115-151226.png).
  • We check if new_screenshot_dir is empty in line 377 but it's not (it contains memory trash), and settings->bools.screenshots_in_content_dir is false, so it still hasn't been initialized.
  • We create a pathname (line 382) with an uninitialized string but a valid filename, and it only works occasionally (when the uninitialized string happens to be a valid directory name?).

A lot of these are educated guesses, but I thought it'd be better to write it up and maybe help someone actually fix it.

Version/Commit

Commit hash b0da8b15794afbb6df6ae30ede16b1a7423c60e8

Environment information
  • OS: macOS (15.0.1, arm64)
  • Compiler: Xcode

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tasks/task_screenshot.c at the screenshot_dump declaration around line 255 and the new_screenshot_dir declaration around line 318. Trace its use in the path construction around lines 377-382, then reproduce the macOS screenshot flow from the listed steps. Done means screenshots save successfully to the expected PNG location without malformed directories.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.