From d1a92aafff55defefcb8cf8f4b045701325088b2 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sun, 27 Jun 2021 22:49:33 -0400 Subject: sdl: increase default worker thread size. This fixes a mysterious, long-standing crash that's been bothering me on ipod6g for ages: a silent stack overflow in the sound mixing thread (which is triggered upon loading a new sound, apparently) will thrash the memory which is located directly before it in the address space. In this case, it was the SDL_ButtonState variable which stores the mouse button state that was being trashed. This was manifesting itself by making the player always run forward, since MOUSE2 is mapped to +forward by default. Fix this by quadrupling the stack size of SDL-spawned threads (not the main thread) from 1 KB to 4 KB. Change-Id: I2d7901b7cee1e3ceb1ccdebb38d4ac5b7ea730e1 --- apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c b/apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c index b9bd8735d3..d393e50e14 100644 --- a/apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c +++ b/apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c @@ -42,20 +42,25 @@ static void rbsdl_runthread(void) SDL_RunThread(args); } +#define RBSDL_THREAD_STACK_SIZE (DEFAULT_STACK_SIZE * 4) #define MAX_THREAD 4 static char names[MAX_THREAD][16]; -static long stacks[MAX_THREAD][DEFAULT_STACK_SIZE / sizeof(long)]; +static long stacks[MAX_THREAD][RBSDL_THREAD_STACK_SIZE / sizeof(long)]; int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) { static int threadnum = 0; + + if(threadnum >= MAX_THREAD) + return -1; + snprintf(names[threadnum], 16, "sdl_%d", threadnum); while(global_args) rb->yield(); /* busy wait, pray that this works */ global_args = args; - thread->handle = rb->create_thread(rbsdl_runthread, stacks[threadnum], DEFAULT_STACK_SIZE, + thread->handle = rb->create_thread(rbsdl_runthread, stacks[threadnum], RBSDL_THREAD_STACK_SIZE, 0, names[threadnum] /* collisions allowed? */ IF_PRIO(, PRIORITY_BUFFERING) // this is used for sound mixing IF_COP(, CPU)); -- cgit v1.2.3