Skip to content

Commit fc5fce8

Browse files
author
Maeve Sproule
committed
Fix "sdl2::ttf::init incorrectly incorrectly uses the last OS error"
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 Rust-SDL2#1347.
1 parent 77c1eb4 commit fc5fce8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ when upgrading from a version of rust-sdl2 to another.
2020

2121
[PR #1337](https://github.com/Rust-SDL2/rust-sdl2/pull/1337) Fix "Cannot initialize Sdl from more than one thread" for tests / CI
2222

23+
[PR #1348](https://github.com/Rust-SDL2/rust-sdl2/pull/1348) Fix "sdl2::ttf::init incorrectly incorrectly uses the last OS error"
24+
2325
### v0.35.2
2426

2527
[PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks

src/sdl2/ttf/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ pub fn init() -> Result<Sdl2TtfContext, InitError> {
124124
} else if ttf::TTF_Init() == 0 {
125125
Ok(Sdl2TtfContext)
126126
} else {
127-
Err(InitError::InitializationError(io::Error::last_os_error()))
127+
Err(InitError::InitializationError(io::Error::new(
128+
io::ErrorKind::Other,
129+
get_error(),
130+
)))
128131
}
129132
}
130133
}

0 commit comments

Comments
 (0)