gtk-rs / gtk4-rs

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

GTK fails to init #14

Closed bilelmoussaoui closed 4 years ago

bilelmoussaoui commented 4 years ago

I have just start to play with gtk4, the first run wasn't a success sadly as I'm getting this when running any examples from gtk-rs/examples4.

thread 'main' panicked at 'GTK has not been initialized. Call `gtk::init` first.', /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Here's the backtrace with RUST_BACKTRACE=full

hread 'main' panicked at 'GTK has not been initialized. Call `gtk::init` first.', /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333:5
stack backtrace:
   0:     0x56540f4004b4 - backtrace::backtrace::libunwind::trace::h7b0eb74108f5983f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1:     0x56540f4004b4 - backtrace::backtrace::trace_unsynchronized::h1b47ddc501b76c75
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2:     0x56540f4004b4 - std::sys_common::backtrace::_print_fmt::hdb3e11118348d382
                               at src/libstd/sys_common/backtrace.rs:77
   3:     0x56540f4004b4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9a91dd8c51296d48
                               at src/libstd/sys_common/backtrace.rs:61
   4:     0x56540f418d6c - core::fmt::write::h0abb1a448222f5be
                               at src/libcore/fmt/mod.rs:1028
   5:     0x56540f3fed37 - std::io::Write::write_fmt::heafd3457e1ab0a67
                               at src/libstd/io/mod.rs:1412
   6:     0x56540f40284e - std::sys_common::backtrace::_print::hce8ebf3707f77321
                               at src/libstd/sys_common/backtrace.rs:65
   7:     0x56540f40284e - std::sys_common::backtrace::print::hab52fb573eb13c01
                               at src/libstd/sys_common/backtrace.rs:50
   8:     0x56540f40284e - std::panicking::default_hook::{{closure}}::hb9a3113d679899b0
                               at src/libstd/panicking.rs:188
   9:     0x56540f402541 - std::panicking::default_hook::haba400789ba2c5f0
                               at src/libstd/panicking.rs:205
  10:     0x56540f402e9b - std::panicking::rust_panic_with_hook::hf1dd057170b2fcea
                               at src/libstd/panicking.rs:464
  11:     0x56540f3fb1b3 - std::panicking::begin_panic::he6705b84de17ade4
                               at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/panicking.rs:400
  12:     0x56540f3e9992 - gtk4::auto::functions::is_initialized::he3968962883b7744
                               at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333
  13:     0x56540f3e8ed7 - gtk4::rt::init::h7aeefe6a0a29e070
                               at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/rt.rs:97
  14:     0x56540f3ea203 - gtk4::application::<impl gtk4::auto::application::Application>::new::h51ba65495792adae
                               at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/application.rs:12
  15:     0x56540f3e7a16 - basic::main::h475eff658a69716b
                               at src/bin/basic.rs:31
  16:     0x56540f3e5d20 - std::rt::lang_start::{{closure}}::h27829dcc20b89d0f
                               at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/rt.rs:61
  17:     0x56540f402913 - std::rt::lang_start_internal::{{closure}}::hefa3bdc6af77c7a5
                               at src/libstd/rt.rs:48
  18:     0x56540f402913 - std::panicking::try::do_call::h1fdd22ace65aadbc
                               at src/libstd/panicking.rs:287
  19:     0x56540f40411a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:83
  20:     0x56540f40337d - std::panicking::try::hfb89dbe42a15da49
                               at src/libstd/panicking.rs:265
  21:     0x56540f40337d - std::panic::catch_unwind::hf2d0ee7f8aef5e8d
                               at src/libstd/panic.rs:396
  22:     0x56540f40337d - std::rt::lang_start_internal::ha3597cbe02c510ac
                               at src/libstd/rt.rs:47
  23:     0x56540f3e5cf9 - std::rt::lang_start::h82983fdaabb50d4e
                               at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/rt.rs:61
  24:     0x56540f3e7b2a - main
  25:     0x7f897a5841a3 - __libc_start_main
  26:     0x56540f3e51fe - _start
  27:                0x0 - <unknown>

Expect some other issues and hopefully pull requests to fix them :)

sdroege commented 4 years ago

The assertion about initialization has to be removed from the gtk::Application constructor, at least. gtk::Application::run() is initializing GTK by itself already when needed.

bilelmoussaoui commented 4 years ago

The assertion about initialization has to be removed from the gtk::Application constructor, at least. gtk::Application::run() is initializing GTK by itself already when needed.

I looked a bit at the code and it seems the assert is skipped https://github.com/gtk-rs/gtk4/blob/master/src/application.rs#L11

sdroege commented 4 years ago

https://github.com/gtk-rs/gtk4/blob/master/src/auto/functions.rs#L333 is where the panic comes from according to your backtrace. That obviously makes no sense and it should not assert that here.