fix(libSceNgs2.native): keep the system list and its mutex alive through static teardown #1197
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1197"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by gookie-dev on 2026-10-07T17:16:10Z.
What
NGS2 looks up every system, rack and voice handle in a function-local
std::vectorguarded by a function-localstd::recursive_mutex(System.cpp). Both were destroyed with the other statics when the process exits.std::exitruns the destructors on the exiting thread while the title's other threads keep running, so an audio thread that renders during exit finds the freed vector:sceNgs2SystemRenderreturnsSCE_NGS2_ERROR_INVALID_SYSTEM_HANDLE(the freed vector's first element now holds the allocator's free-list pointer), andNgs2FindVoicefromsceNgs2VoiceGetState) dereferences freed memory and segfaults.Both objects are now allocated once and never destroyed, as other driver state that must outlive static teardown already is (
Draw.cpp,Pipeline.cpp,Recorder.cpp).Tested
Pop!_OS 24.04 (kernel 7.1.5), GCC 13.3.0, CMake 3.28.3, Ninja, Release,
BUILD_TESTING=ON, SPIRV-Tools validation off, NVIDIA GeForce RTX 4050 Laptop GPU.libspackaging pass.ctest: 390 of 390 pass.ngs2_rendernow registers anatexithandler before its first NGS2 call. The handler runs after the library's statics are destroyed, renders a system created at the end ofmainand destroys it. Without this change it fails on that render (sceNgs2SystemRenderdoes not returnSCE_NGS2_OK).main+ #1020, #861, #1038 and #1100, which it needs to reach its menu here. The title was closed throughSDL_QUIT(SIGTERM) after 20 to 45 s. Without this change 4 of 6 runs printedError: sceNgs2SystemRender() 804A0230and 4 of 6 ended with a segfault (the core dump examined:Ngs2FindVoicecalled fromsceNgs2VoiceGetState). With it, 6 of 6 exited with status 0 and no NGS2 error.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Ngs2Render.cppor NGS2)