Segfault with `gtk_notebook_append_page` and a Webkit Web View

Hello, I’m making a browser with WebKit, GTK, and Vala. I am implementing tabs via a Gtk.Notebook, however I get a segfault when adding pages to it via a callback event. I can add them during my ApplicationWindow subclass constructor as normal. Here are some relevant snippets:

/* class based on Gtk.ApplicationWindow */
public ApplicationWindow (Sail.Application app, WebKit.Settings settings) {
	application = app;
	this.settings = settings;

	open_tab ("https://www.youtube.com/"); //Opens tab fine
	open_tab (null); //Opens tab fine

}
// Connected to Gtk.Button.clicked via .ui file, fails when handled
public void open_tab (string? uri) {
	Tab tab = new Tab ();
	WebView view = new WebView (tab, uri);
	tab_bar.append_page (view, tab); // Segfaults here

	var page = tab_bar.get_page (view);
	page.tab_expand = true;
	page.tab_fill = true;
}
/* class based on WebKit.WebView */
public WebView (Tab tab, string? uri) {
	const string DEFAULT_PAGE = "https://search.brave.com/";
	this.tab = tab;

	notify["favicon"].connect ((s, p) => {
		tab.set_icon (get_favicon ());
	});

	load_uri (uri != null ? uri : DEFAULT_PAGE);
}

Any and all help/questions are appreciated!

The Gtk.Button::clicked signal has signature void (Gtk.Button, void *) (or whatever is untyped pointer in Vala, my Vala is rusty – no pun intended). So you’re effectively using the clicked Gtk.Button as if it was a string?, which clearly isn’t gonna fly well.

You need to have a specific handler for your button that has the right signature, which than calls your open_tab(null).

Good point on the function, but this still segfaults on the denoted function above append_page either way. Testing with other widgets also causes the segfault.

EDIT: I forgot to add [GtkCallback], which is something that someone without Vala experience (myself) would not catch.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.