Skip to content

Commit

Permalink
Use SDL_GetError for sdl2::ttf::init instead of the last OS error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Maeve Sproule committed Nov 4, 2023
1 parent 77c1eb4 commit dd3721b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ when upgrading from a version of rust-sdl2 to another.

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

[PR #1348](https://github.com/Rust-SDL2/rust-sdl2/pull/1348) Use `SDL_GetError` for `sdl2::ttf::init` instead of the last OS error

### v0.35.2

[PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks
Expand Down
5 changes: 4 additions & 1 deletion src/sdl2/ttf/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ pub fn init() -> Result<Sdl2TtfContext, InitError> {
} 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(),
)))
}
}
}
Expand Down

0 comments on commit dd3721b

Please sign in to comment.