Fix thread names being set to garbage (#3985)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

SetThreadName gets passed an std::string's c_str whose pointer gets invalidated by the assignment of g_curthread->name, resulting in broken thread names further down the line
This commit is contained in:
jas0n098 2026-02-03 08:58:22 +00:00 committed by GitHub
parent e2f3a0f750
commit 8da0b58aaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,7 +175,7 @@ bool AccurateSleep(const std::chrono::nanoseconds duration, std::chrono::nanosec
// Sets the debugger-visible name of the current thread.
void SetCurrentThreadName(const char* name) {
if (Libraries::Kernel::g_curthread) {
Libraries::Kernel::g_curthread->name = std::string{name};
Libraries::Kernel::g_curthread->name = name;
}
SetThreadDescription(GetCurrentThread(), UTF8ToUTF16W(name).data());
}
@ -190,7 +190,7 @@ void SetThreadName(void* thread, const char* name) {
#if !defined(_WIN32) || defined(_MSC_VER)
void SetCurrentThreadName(const char* name) {
if (Libraries::Kernel::g_curthread) {
Libraries::Kernel::g_curthread->name = std::string{name};
Libraries::Kernel::g_curthread->name = name;
}
#ifdef __APPLE__
pthread_setname_np(name);
@ -219,7 +219,7 @@ void SetThreadName(void* thread, const char* name) {
#if defined(_WIN32)
void SetCurrentThreadName(const char*) {
if (Libraries::Kernel::g_curthread) {
Libraries::Kernel::g_curthread->name = std::string{name};
Libraries::Kernel::g_curthread->name = name;
}
// Do Nothing on MinGW
}