Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
LeandroLP23:fix/agc-address-space-cache-exit
Oct 8, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
LeandroLP23:fix/agc-address-space-cache-exit

Conversation

@LeandroLP23

@LeandroLP23 LeandroLP23 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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 219a1cf.

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

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

@LeandroLP23
LeandroLP23 force-pushed the fix/agc-address-space-cache-exit branch from 2b7f71b to b11d62c Compare October 7, 2026 08:53
ClearImageMirrors drops the mirror map before the device is destroyed,
but the current address space in Spaces() still held its mirrors, so
they were freed by the cache's static destructor from the driver's DLL
detach, after the Vulkan driver was unloaded, and every exit crashed on
Windows. The teardown now releases the current address space too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeandroLP23
LeandroLP23 force-pushed the fix/agc-address-space-cache-exit branch from b11d62c to db26339 Compare October 7, 2026 08:53
@LeandroLP23 LeandroLP23 changed the title fix(agc): keep the address space cache alive at process exit fix(agc): release the current address space with the image mirrors Oct 7, 2026
@github-actions github-actions Bot added the agc libSceAgc* label Oct 7, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants