fix(agc): release the current address space with the image mirrors #1071

Merged
LeandroLP23 merged 1 commit from upstream-pr/1071 into main 2026-10-08 05:50:28 +00:00
LeandroLP23 commented 2026-10-07 08:35:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-07T08:35:52Z.


What

Closing a title on Windows crashes after #849: its ClearImageMirrors drops the mirror map before the device is destroyed, but the current address space in Spaces() (GuestBufferMemory.cpp) still holds shared references to the same mirrors. They live on until the cache's function-local static is destroyed from libSceAgcDriver.prx's DLL detach, and their pooled buffers are then freed through Vulkan after the Vulkan driver has been unloaded:

FATAL: unhandled exception 0xc0000005 on thread ...
  execute of 0x00007ffaf1cf8760

Stack, symbolized against the build's libSceAgcDriver.prx:

Offset Symbol
+0xd9159 Buffer::~Buffer() (from Buffer::release())
+0x1a23fa BufferPool::~BufferPool()
+0x526a7b _Sp_counted_ptr_inplace<ImageMirror>::_M_dispose()
+0x527131 _Sp_counted_ptr_inplace<GuestBufferMemory::AddressSpace>::_M_dispose()
+0x12fcbf __tcf_...Spaces()::cache (static destructor)
+0x12a4, +0x12ef _CRT_INIT, DllMainCRTStartup

ClearImageMirrors now also releases the current address space, so its mirrors are freed in the device teardown with the rest, while the device exists. The next use rebuilds the address space, as after the existing waiter drop.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with BUILD_TESTING=ON, AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), main 219a1cf8.

DOOM Shareware homebrew PPSA99666 01.001.000 (lowbit/ps5-doom v1.1.0, the build in #690), converted with --windows, closed with the window's close button:

main this PR
Closed in the launcher menu crash, exit 139 (2 of 2) exit 0 (3 of 3)
Closed after starting E1M1 crash, exit 139 exit 0
  • Full ctest: 382/383 passed; the failure is #825, which also fails on unmodified main on this GPU.
  • The crash was only reproduced on this AMD setup. Not tested on NVIDIA, Intel or Linux.
  • None of the six open PRs that touch GuestBufferMemory.cpp (#290, #426, #639, #943, #1046, #1051) conflicts with this change; #639 calls Spaces() without changing it.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4770091753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1071). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-07T08:35:52Z. --- ### What Closing a title on Windows crashes after #849: its `ClearImageMirrors` drops the mirror map before the device is destroyed, but the current address space in `Spaces()` (`GuestBufferMemory.cpp`) still holds shared references to the same mirrors. They live on until the cache's function-local static is destroyed from `libSceAgcDriver.prx`'s DLL detach, and their pooled buffers are then freed through Vulkan after the Vulkan driver has been unloaded: ``` FATAL: unhandled exception 0xc0000005 on thread ... execute of 0x00007ffaf1cf8760 ``` Stack, symbolized against the build's `libSceAgcDriver.prx`: | Offset | Symbol | |---|---| | +0xd9159 | `Buffer::~Buffer()` (from `Buffer::release()`) | | +0x1a23fa | `BufferPool::~BufferPool()` | | +0x526a7b | `_Sp_counted_ptr_inplace<ImageMirror>::_M_dispose()` | | +0x527131 | `_Sp_counted_ptr_inplace<GuestBufferMemory::AddressSpace>::_M_dispose()` | | +0x12fcbf | `__tcf_...Spaces()::cache` (static destructor) | | +0x12a4, +0x12ef | `_CRT_INIT`, `DllMainCRTStartup` | `ClearImageMirrors` now also releases the current address space, so its mirrors are freed in the device teardown with the rest, while the device exists. The next use rebuilds the address space, as after the existing waiter drop. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with `BUILD_TESTING=ON`, AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), `main` 219a1cf8. DOOM Shareware homebrew PPSA99666 01.001.000 (lowbit/ps5-doom v1.1.0, the build in #690), converted with `--windows`, closed with the window's close button: | | `main` | this PR | |---|---|---| | Closed in the launcher menu | crash, exit 139 (2 of 2) | exit 0 (3 of 3) | | Closed after starting E1M1 | crash, exit 139 | exit 0 | - Full `ctest`: 382/383 passed; the failure is #825, which also fails on unmodified `main` on this GPU. - The crash was only reproduced on this AMD setup. Not tested on NVIDIA, Intel or Linux. - None of the six open PRs that touch `GuestBufferMemory.cpp` (#290, #426, #639, #943, #1046, #1051) conflicts with this change; #639 calls `Spaces()` without changing it. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-08 05:50:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T05:50:24Z.


Checked the diff: Spaces().current is released inside ClearImageMirrors, after the mirror map swap and while the device still exists, same pattern as the waiter drop at GuestBufferMemory.cpp:973. Build and full ctest on top of current main pass (415/415), Linux and Windows CI green. The Windows teardown crash itself is taken from the PR's before/after table; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053304952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1071#issuecomment-6053304952). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T05:50:24Z. --- Checked the diff: `Spaces().current` is released inside `ClearImageMirrors`, after the mirror map swap and while the device still exists, same pattern as the waiter drop at `GuestBufferMemory.cpp:973`. Build and full ctest on top of current `main` pass (415/415), Linux and Windows CI green. The Windows teardown crash itself is taken from the PR's before/after table; 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!1071
No description provided.