Fix crash when taking screenshots on a thread

Forgot that we only enable android JNI on "I/O" threads.

Fixes #20139
This commit is contained in:
Henrik Rydgård 2025-03-21 19:12:07 +01:00
parent 112bd904b8
commit a3a7807aac
3 changed files with 3 additions and 2 deletions

View file

@ -139,6 +139,7 @@ static void WorkerThreadFunc(GlobalThreadContext *global, TaskThreadContext *thr
}
SetCurrentThreadName(thread->name);
// Should we do this on all threads?
if (thread->type == TaskType::IO_BLOCKING) {
AttachThreadToJNI();
}

View file

@ -7,7 +7,7 @@
// To help smart scheduling.
enum class TaskType {
CPU_COMPUTE,
IO_BLOCKING,
IO_BLOCKING, // NOTE: Only these can access scoped storage on Android (they initialize the JNI context).
DEDICATED_THREAD, // These can never get stuck in queue behind others, but are more expensive to launch. Cannot use I/O.
};

View file

@ -361,7 +361,7 @@ ScreenshotResult TakeGameScreenshot(Draw::DrawContext *draw, const Path &filenam
}
if (callback) {
g_threadManager.EnqueueTask(new IndependentTask(TaskType::CPU_COMPUTE, TaskPriority::LOW,
g_threadManager.EnqueueTask(new IndependentTask(TaskType::IO_BLOCKING, TaskPriority::LOW,
[buf = std::move(buf), callback = std::move(callback), filename, fmt, w, h]() {
u8 *flipbuffer = nullptr;
u32 width = w, height = h;