Skip to content

fix init#1459

Merged
jagprog5 merged 3 commits intoRust-SDL2:masterfrom
jagprog5:fix_init_flags
Mar 4, 2025
Merged

fix init#1459
jagprog5 merged 3 commits intoRust-SDL2:masterfrom
jagprog5:fix_init_flags

Conversation

@jagprog5
Copy link
Contributor

The SDL image library can initialize the codecs up front for whatever formats. this is done by calling IMG_Init.

However, it is not necessary. All of the image format that sdl2 support have the same pattern, like here for png, or here for jpg. Before loading the image it will try to load the codec if it is not already loaded.

So a pattern that can be used is:

  1. init with no flags
  2. then on load_texture it will link the codecs as needed, whenever an image of that format is loaded

of note: this is explicitly valid in the docs.

it's legal to call this with zero (no flags set)

Right now via rust bindings, calling

sdl2::image::init(sdl2::image::InitFlag::empty())

gives the cryptic error: "Could not init: ", which is... interesting.

and also, current logic uses, intersects, but this gives success if any of the libs init correctly (but even if one fail then it's not propagated to the caller!), when it should instead give fail only if any of them fail.

@jagprog5 jagprog5 changed the title fix init flags fix init Feb 10, 2025
@Cobrand
Copy link
Member

Cobrand commented Feb 18, 2025

Looks good, but add this to the changelog since there is probably someone out there who will have their code break because of this change.

@jagprog5 jagprog5 merged commit d6de6b2 into Rust-SDL2:master Mar 4, 2025
16 of 17 checks passed
antonilol added a commit to antonilol/rust-sdl2 that referenced this pull request Dec 6, 2025
Cobrand added a commit that referenced this pull request Dec 16, 2025
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.

2 participants