From 69396f97a78c64ecd55d069f9a6054862cf35656 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 28 Feb 2026 17:08:37 +1000 Subject: [PATCH] Fix a threading issue with PS Vita. --- miniaudio.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 4f604440..9e0d8e6b 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -17919,7 +17919,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority int result; pthread_attr_t* pAttr = NULL; -#if !defined(MA_EMSCRIPTEN) && !defined(MA_N3DS) && !defined(MA_SWITCH) && !defined(MA_DREAMCAST) +#if !defined(MA_EMSCRIPTEN) && !defined(MA_N3DS) && !defined(MA_SWITCH) && !defined(MA_DREAMCAST) && !defined(MA_VITA) /* Try setting the thread priority. It's not critical if anything fails here. */ pthread_attr_t attr; if (pthread_attr_init(&attr) == 0) { @@ -17955,6 +17955,23 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority { if (stackSize > 0) { pthread_attr_setstacksize(&attr, stackSize); + } else { + /* + Note for Vita SDK + + When using pthread_attr_t (this path we're in now), the default stack size seems to be too small. If the + pthread_attr_t path is skipped entirely, things work fine. It looks like skipping the call to + pthread_attr_setstacksize(), which happens when stackSize is 0, the chosen stack size is smaller than + what it would be if we skipped the pthread_attr_t path. + + There are two work arounds for this. The first is to always skip the pthread_attr_t path. The second is + to have a specialized path here for Vita and explicitly default to something bigger. I'm doing both. + */ + #if defined(MA_VITA) + { + pthread_attr_setstacksize(&attr, 0x10000); + } + #endif } } #else