libretro / libretro/RetroArch

Hardware context destroy/reset callback not fired after setting av system info

Open
#11,623 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

As discussed on Discord, when a core wants to change resolution, it calls SET_AV_SYSTEM_INFO, which may cause a driver reinit. In the Vulkan driver's case, it appears to do a partial re-initialization.

This causes the pointer returned by GET_HW_RENDER_INTERFACE to be freed, and the core will eventually dereference this pointer next time it renders a frame.

Expected behavior

context_destroy callback to be executed, then context_reset after the driver finishes initializing. Important to note that I'm doing this inside retro_run_frame, as this is where settings changes are detected.

Actual behavior

Neither callback fires, sometimes the core will crash, as the page the allocation is on might still be valid. If you run RetroArch with Application Verifier and the page heap enabled, it will crash every time.

I've worked around this in DuckStation - it will re-request the hw render interface after changing the AV system info. It also logs a warning when this pointer changes.

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 by tracing SET_AV_SYSTEM_INFO from retro_run_frame through the handling of GET_HW_RENDER_INTERFACE and the context_destroy/context_reset callbacks. Reproduce the issue with Application Verifier and page heap, then compare the callback sequence and hardware-render-interface lifetime before and after the AV system information change. Done means the callbacks fire in the expected order and rendering does not dereference a freed pointer.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.