From 2804982d9102e06d4058a25f06059ea8b94200f1 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 12 Nov 2026 22:49:05 -0600 Subject: [PATCH] Fix PltSleepMs() handling of large sleep durations --- src/Platform.c | 10 +++++++--- src/Platform.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Platform.c b/src/Platform.c index 78011bc..a5c0e51 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -108,11 +108,15 @@ void PltSleepMs(int ms) { #if defined(LC_WINDOWS) SleepEx(ms, FALSE); #elif defined(__3DS__) - s64 nsecs = ms * 1000000; + s64 nsecs = (s64)ms * 1000000LL; svcSleepThread(nsecs); #else - useconds_t usecs = ms * 1000; - usleep(usecs); + struct timespec req; + + req.tv_sec = (time_t)(ms / 1000); + req.tv_nsec = (long)(ms % 1000) * 1000000L; + + while (nanosleep(&req, &req) == -1 && errno == EINTR); #endif } diff --git a/src/Platform.h b/src/Platform.h index f219864..bcf4530 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -41,11 +41,13 @@ #include #elif defined(__vita__) #include +#include #include #include #include #elif defined(__WIIU__) #include +#include #include #include #include @@ -59,6 +61,7 @@ #else #include #include +#include #include #include #include