fix(avplayer): close safely from event callbacks #5944

Merged
Ondra97 merged 1 commit from upstream-pr/5944 into main 2026-10-16 20:29:32 +00:00
Ondra97 commented 2026-10-14 16:38:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T16:38:01Z.


What

Closing an AvPlayer from its event callback tried to join the controller thread that was running that callback. std::thread::join throws for a self-join, terminating the process during destruction.

When the controller closes its own player, detach that thread and retain a closure marker independently of the player. After the callback returns, the loop reads that marker and exits before accessing the destroyed player's locks or event queue. Closure from another thread still joins the controller normally.

The regression closes from the ready callback and the end-of-playback stop callback, creates a replacement player inside each callback, and checks that media allocations are released. It reuses the existing generated movie fixture and runs separately from the playback suite.

Tested

Windows 11 Pro 10.0.26300, supported WinLibs GCC 15.2.0, Release, main e34c47921.

  • The new callback-close case fails on main with a std::system_error from self-joining in the player destructor. With the fix it passes three consecutive runs (2.44 s total); the final test dispatcher layout also passes (0.88 s).
  • The existing guest_avplayer playback suite passes (4.16 s). Full default Windows build, conventions and whitespace checks pass.
  • Reviewed #5846 and #1601, which change source buffering and the shared movie fixture, and separated the test dispatch insertion from #5846. Neither implements callback closure. The repository overlap checker reports no conflicts in the shared-file inventory.
  • Linux and retail-title runs were not performed locally. No performance claim.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes, Codex

Full platform runtime CI requires a write-access collaborator to dispatch it under repository policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4861153089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5944). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T16:38:01Z. --- ### What Closing an AvPlayer from its event callback tried to join the controller thread that was running that callback. `std::thread::join` throws for a self-join, terminating the process during destruction. When the controller closes its own player, detach that thread and retain a closure marker independently of the player. After the callback returns, the loop reads that marker and exits before accessing the destroyed player's locks or event queue. Closure from another thread still joins the controller normally. The regression closes from the ready callback and the end-of-playback stop callback, creates a replacement player inside each callback, and checks that media allocations are released. It reuses the existing generated movie fixture and runs separately from the playback suite. ### Tested Windows 11 Pro 10.0.26300, supported WinLibs GCC 15.2.0, Release, main `e34c47921`. - The new callback-close case fails on main with a `std::system_error` from self-joining in the player destructor. With the fix it passes three consecutive runs (2.44 s total); the final test dispatcher layout also passes (0.88 s). - The existing `guest_avplayer` playback suite passes (4.16 s). Full default Windows build, conventions and whitespace checks pass. - Reviewed #5846 and #1601, which change source buffering and the shared movie fixture, and separated the test dispatch insertion from #5846. Neither implements callback closure. The repository overlap checker reports no conflicts in the shared-file inventory. - Linux and retail-title runs were not performed locally. No performance claim. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes, Codex Full platform runtime CI requires a write-access collaborator to dispatch it under repository policy.
github-actions[bot] commented 2026-10-15 12:12:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:12:03Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 5995 core/libs/prx/libSceAvPlayer/CMakeLists.txt L13, L18-19

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1601 core/libs/tests/GuestAvPlayer.cpp
PR 6044 core/libs/prx/libSceAvPlayer/CMakeLists.txt
core/libs/tests/GuestAvPlayer.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191747273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5944#issuecomment-6191747273). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:12:03Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 5995](https://www.github.com/boykopovar/AnyPS5/pull/5995) | `core/libs/prx/libSceAvPlayer/CMakeLists.txt` [L13](https://github.com/boykopovar/AnyPS5/blob/93e54cedd3dd49eabf1c589f020b54758e0b6461/core/libs/prx/libSceAvPlayer/CMakeLists.txt#L13), [L18-19](https://github.com/boykopovar/AnyPS5/blob/93e54cedd3dd49eabf1c589f020b54758e0b6461/core/libs/prx/libSceAvPlayer/CMakeLists.txt#L18-L19) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1601](https://www.github.com/boykopovar/AnyPS5/pull/1601) | `core/libs/tests/GuestAvPlayer.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libSceAvPlayer/CMakeLists.txt`<br>`core/libs/tests/GuestAvPlayer.cpp` |
jotitadev commented 2026-10-15 20:04:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T20:04:10Z.

Review: COMMENTED


Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head 5474b7756 merged onto main 44df21632.

  • Builds; guest_avplayer and the new guest_avplayer_callback_close pass.
  • With AvPlayer.hpp/Player.cpp from main: guest_avplayer_callback_close aborts with std::system_error / Resource deadlock avoided (glibc's EDEADLK for the self-join), the Linux counterpart of the Windows failure in the description. guest_avplayer still passes.

Non-GPU suite (ctest -E "^agc"): same result as main; only file_writer_binary and file_writer_text fail, and they fail on main too on this machine (Ubuntu 26.04 coreutils).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5539185841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5944#pullrequestreview-5539185841). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T20:04:10Z. **Review:** COMMENTED --- Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head `5474b7756` merged onto `main` `44df21632`. - Builds; `guest_avplayer` and the new `guest_avplayer_callback_close` pass. - With `AvPlayer.hpp`/`Player.cpp` from `main`: `guest_avplayer_callback_close` aborts with `std::system_error` / `Resource deadlock avoided` (glibc's EDEADLK for the self-join), the Linux counterpart of the Windows failure in the description. `guest_avplayer` still passes. Non-GPU suite (`ctest -E "^agc"`): same result as `main`; only `file_writer_binary` and `file_writer_text` fail, and they fail on `main` too on this machine (Ubuntu 26.04 coreutils). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
adriadam10 commented 2026-10-16 18:53:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T18:53:32Z.


Checked on Linux: build and ctest of AvPlayer/libs (34 tests) pass; with AvPlayer.hpp/Player.cpp reverted, guest_avplayer_callback_close fails, so it exercises the fix. The detached controller only touches the shared closed flag after the callback returns, and the flag outlives the player via the lambda capture. Matches jotitadev's Linux run. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222527953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5944#issuecomment-6222527953). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T18:53:32Z. --- Checked on Linux: build and ctest of AvPlayer/libs (34 tests) pass; with `AvPlayer.hpp`/`Player.cpp` reverted, `guest_avplayer_callback_close` fails, so it exercises the fix. The detached controller only touches the shared closed flag after the callback returns, and the flag outlives the player via the lambda capture. Matches jotitadev's Linux run. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5944
No description provided.