From 35abb38b288592ebd7f56d92fd6c4ce95d45b865 Mon Sep 17 00:00:00 2001 From: Avery Felts Date: Tue, 17 Nov 2026 17:34:37 -0700 Subject: [PATCH] fix(psvr2): leave an ioData buffer's length alone where macOS refuses to change it startReader set the length of each endpoint's ioDataWithCapacity buffer to its transfer size. Some macOS versions give such a buffer its capacity as its length and throw ioDataSetLengthException on any change, which ended metalvrd as soon as a PlayStation VR2 was found. The length is set only when it differs, the refusal is caught and logged, and a buffer shorter than the transfer leaves that endpoint unopened instead. --- daemon/backend_psvr2.mm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/daemon/backend_psvr2.mm b/daemon/backend_psvr2.mm index dd59037..571985d 100644 --- a/daemon/backend_psvr2.mm +++ b/daemon/backend_psvr2.mm @@ -226,7 +226,21 @@ bool startReader(int interface, int endpoint, size_t size, const char *label, logInfo("psvr2: the %s endpoint (%02x) did not open: %s", label, endpoint, error.localizedDescription.UTF8String); return false; } - r.data.length = size; + // a read asks for the buffer's length. some macOS versions give an ioData buffer its capacity as its length and + // refuse any change to it (NSException ioDataSetLengthException, which ended metalvrd); others start it at 0 + if (r.data.length != size) { + @try { + r.data.length = size; + } @catch (NSException *exception) { + logInfo("psvr2: the %s endpoint's buffer keeps %lu bytes (%s)", label, + static_cast(r.data.length), exception.reason.UTF8String); + } + } + if (r.data.length < size) { + logInfo("psvr2: the %s endpoint's buffer has %lu of %zu bytes", label, static_cast(r.data.length), + size); + return false; + } r.handle = std::move(handle); r.name = label; readers_.push_back(r);