From 817121e4912feb2270a6ebe663c60ca333481544 Mon Sep 17 00:00:00 2001 From: Maeve Sproule Date: Sat, 4 Nov 2023 14:10:25 -0600 Subject: [PATCH] ttf: Use SDL_GetError for initialization errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the code use the last OS error. However, not all errors returned by `TTF_Init` are OS errors, and the expected behaviour is that the caller instead use `SDL_GetError` when an error is encountered. To limit breakage for existing application the error is still returned as an `io::Error`, albeit one with `io::ErrorKind::Other`. It is worth noting that this does lead to an observable difference in behaviour for callers – the error has a different kind – although any code that is inspecting this was already relying on an unreliable source of data. This fixes issue #1347. --- src/sdl2/ttf/context.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sdl2/ttf/context.rs b/src/sdl2/ttf/context.rs index c3e7a0b731d..3a4b7ed94b4 100644 --- a/src/sdl2/ttf/context.rs +++ b/src/sdl2/ttf/context.rs @@ -124,7 +124,10 @@ pub fn init() -> Result { } else if ttf::TTF_Init() == 0 { Ok(Sdl2TtfContext) } else { - Err(InitError::InitializationError(io::Error::last_os_error())) + Err(InitError::InitializationError(io::Error::new( + io::ErrorKind::Other, + get_error(), + ))) } } }