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

Segfault if trying to use certain builders before GTK is initialized #1807

Closed
anna-hope opened this issue Jul 23, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@anna-hope
Copy link

anna-hope commented Jul 23, 2024

(This is partially duplicated from gtk-rs/gir#1590, because I think that's where the fix should ultimately go, even though the bug itself affects gtk4-rs)

Using some builders before initializing GTK can cause a segfault. Instead, the generated builder should check if GTK has been initialized, and panic if not.

use gtk4::prelude::*;
use gtk4::{Application, ApplicationWindow, glib};

const APP_ID: &str = "me.annahope.gtk4-rs-segfault";

fn build_ui(app: &Application) {
    let window = ApplicationWindow::builder()
        .application(app)
        .title("Segfault")
        .build();  // Segfaults if GTK hasn't been initialized.

    window.present();
}

fn main() -> glib::ExitCode {
    let app = Application::builder().application_id(APP_ID).build();
    // app.connect_activate(build_ui); // Doesn't segfault, as expected
    build_ui(&app); // Segfaults.
    app.run()
}
Stacktrace
gtk_style_provider_get_settings 0x0000000101dfd1c4
gtk_css_value_initial_compute 0x0000000101e926bc
gtk_css_static_style_compute_value 0x0000000101ea2384
gtk_css_static_style_new_compute 0x0000000101ea0ebc
gtk_css_static_style_get_default 0x0000000101ea0c78
gtk_css_node_init 0x0000000101e94ca4
g_type_create_instance 0x00000001015bf428
g_object_new_internal 0x00000001015ab838
g_object_new_with_properties 0x00000001015ab0e4
gtk_css_widget_node_new 0x0000000101eaa4ac
gtk_widget_init 0x0000000101e4124c
g_type_create_instance 0x00000001015bf428
g_object_new_internal 0x00000001015ab838
g_object_new_with_properties 0x00000001015ab0b0
glib::object::Object::new_internal object.rs:1490
glib::object::Object::with_mut_values object.rs:1425
glib::object::ObjectBuilder<O>::build object.rs:1634
gtk4::auto::application_window::ApplicationWindowBuilder::build application_window.rs:420
gtk4_segfault::build_ui main.rs:7
gtk4_segfault::main main.rs:18
core::ops::function::FnOnce::call_once function.rs:250
std::sys_common::backtrace::__rust_begin_short_backtrace backtrace.rs:155
std::rt::lang_start::{{closure}} rt.rs:159
[Inlined] core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once function.rs:284
[Inlined] std::panicking::try::do_call panicking.rs:559
[Inlined] std::panicking::try panicking.rs:523
[Inlined] std::panic::catch_unwind panic.rs:149
[Inlined] std::rt::lang_start_internal::{{closure}} rt.rs:141
[Inlined] std::panicking::try::do_call panicking.rs:559
[Inlined] std::panicking::try panicking.rs:523
[Inlined] std::panic::catch_unwind panic.rs:149
std::rt::lang_start_internal rt.rs:141
std::rt::lang_start rt.rs:158
main 0x0000000100edbbd0
start 0x000000019a4b60e0
@anna-hope anna-hope added the bug Something isn't working label Jul 23, 2024
@bilelmoussaoui
Copy link
Member

This is now fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants