From 3395e4ea10ffbbbc6f0da03518682cb04e46493d Mon Sep 17 00:00:00 2001 From: Austin Doupnik Date: Thu, 14 Sep 2023 01:03:14 -0700 Subject: [PATCH] Fix #1323: Reset IS_MAIN_THREAD_DECLARED on drop --- changelog.md | 2 ++ src/sdl2/sdl.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 76e35bdeda..3321a8cb06 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,8 @@ when upgrading from a version of rust-sdl2 to another. [PR #1332](https://github.com/Rust-SDL2/rust-sdl2/pull/1332) Fix `size_hint` implementations for `{audio,video,render}::DriverIterator` +[PR #1337](https://github.com/Rust-SDL2/rust-sdl2/pull/1337) Fix "Cannot initialize Sdl from more than one thread" for tests / CI + ### v0.35.2 [PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs index d5e1cd53fc..dc8f781c93 100644 --- a/src/sdl2/sdl.rs +++ b/src/sdl2/sdl.rs @@ -86,7 +86,7 @@ impl Sdl { IS_MAIN_THREAD.with(|is_main_thread| { if was_main_thread_declared { if !is_main_thread.get() { - return Err("Cannot initialize `Sdl` from more than once thread.".to_owned()); + return Err("Cannot initialize `Sdl` from more than one thread.".to_owned()); } } else { is_main_thread.set(true); @@ -209,6 +209,7 @@ impl Drop for SdlDrop { unsafe { sys::SDL_Quit(); } + IS_MAIN_THREAD_DECLARED.swap(false, Ordering::SeqCst); } } }