Currently, trying to use some builders before initializing GTK can cause a segfault. Instead, the generated builder should check if GTK has been initialized, and panic if not.
Minimal example
```rust
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);
build_ui(&app); // Segfaults.
app.run()
}
```
I briefly investigated the builder_properties to see if we could set some field there, but couldn't find an easy way to add one. I could look into it further, but I am brand new to this project and GTK overall, so perhaps there is a better way to accomplish this that I don't know about.
Currently, trying to use some builders before initializing GTK can cause a segfault. Instead, the generated builder should check if GTK has been initialized, and panic if not.
Minimal example
```rust 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); build_ui(&app); // Segfaults. app.run() } ```I tried fixing this naively by adding a check to the builder codegen code https://github.com/anna-hope/gir/commit/a3ee2522917a49578fb654cf7a9523d5396ae9a3, but then realized that we definitely can't do this for all builders because:
I briefly investigated the
builder_properties
to see if we could set some field there, but couldn't find an easy way to add one. I could look into it further, but I am brand new to this project and GTK overall, so perhaps there is a better way to accomplish this that I don't know about.