gtk-rs / gtk4-rs

Rust bindings of GTK 4
https://gtk-rs.org/gtk4-rs/
MIT License
1.9k stars 174 forks source link

gtk::disable_setlocale() shouldn't panic if called before gtk::init() #195

Closed Cogitri closed 3 years ago

Cogitri commented 3 years ago

When calling gtk::disable_setlocale() after gtk::init(), GTK prints the following warning:

(dev.Cogitri.Health:140494): Gtk-WARNING **: 19:35:21.489: gtk_disable_setlocale() must be called before gtk_init()

However, when calling it before gtk::init() gtk-rs panics with:

thread 'main' panicked at 'GTK has not been initialized. Call `gtk::init` first.', /var/home/rasmus/Projects/Jinsei/build/target/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/6301405/gtk4/src/auto/functions.rs:129:5
bilelmoussaoui commented 3 years ago

It needs assertions = "skip" set on the gir file I guess. Or maybe better make it return Result<(), BoolError> and check that !gtk::is_initialized() before calling gtk_disable_setlocale.

cc @sdroege, the same issue affects gtk3.

sdroege commented 3 years ago

Yeah there will be more such functions. Someone who actually knows GTK needs to go over those at some point :)

bilelmoussaoui commented 3 years ago

@Cogitri want to send a patch for this one? :)

Cogitri commented 3 years ago

Sure, I can go through those and disable the assert. Not sure if a Result makes sense when it's a programmer error to call it after gtk::init(). Personally, I'd rather panic!()