Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent users from creating Sdl2TtfContext out of nothing and use SDL's reference counting init/quit #1437

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

antonilol
Copy link
Contributor

Detailed description of the changes are in the commit messages

and various other changes, including:
- allow multiple `ttf::init` calls, the same way it works with TTF_Init
- return last sdl error instead of I/O error (like stale pr Rust-SDL2#1348, fixes Rust-SDL2#1347 and closes Rust-SDL2#1348)
- implement `Clone` for `Sdl2TtfContext`, SDL C code will do the reference counting
- make `ttf::font::internal_*` `pub(super)`
- make `ttf::font::Font::raw` safe (obtaining a raw pointer is safe, using it is unsafe)
Err(InitError::InitializationError(io::Error::last_os_error()))
}
#[doc(alias = "TTF_Init")]
pub fn init() -> Result<Sdl2TtfContext, String> {
Copy link
Contributor Author

@antonilol antonilol Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the error type to String here (like in other functions in this library that only return an error from sdl directly), but this specifically will break in an annoying way because now the error does not implement std::error::Error anymore (relevant: #942, #1053, #1424).

I feel like introducing a struct that wraps String (like pub struct SDLError(String);) and implements std::error::Error and Display. This will (in the future) also allow other enums in this crate that can contain an SDL error string to return it from std::error::Error::source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant