Prevent users from creating Sdl2TtfContext out of nothing and use SDL's reference counting init/quit#1437
Merged
antonilol merged 3 commits intoRust-SDL2:masterfrom Mar 8, 2025
Merged
Conversation
antonilol
commented
Oct 8, 2024
| Err(InitError::InitializationError(io::Error::last_os_error())) | ||
| } | ||
| #[doc(alias = "TTF_Init")] | ||
| pub fn init() -> Result<Sdl2TtfContext, String> { |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
|
@antonilol Looks good to me. Please resolve conflict then squash merge |
jagprog5
approved these changes
Mar 8, 2025
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detailed description of the changes are in the commit messages