Skip to content

Commit

Permalink
ttf: Use SDL_GetError for initialization errors
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 817121e
Showing 1 changed file with 4 additions and 1 deletion.
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 817121e

Please sign in to comment.