gtkd-developers/GtkD

Builder, Dialogs, and SegFaults during garbage collection

Opened this issue · 1 comments

I have an issue that causes my program to crash if a garbage collection cycle is performed after a dialog is closed.
However, the issue only occurs if the dialog contains children that were constructed by a GtkBuilder.

Essentially:

auto dialog = /* create dialog */;
auto builder = /* create builder */;
auto widget = builder.getObject("widget_id");
dialog.getContentArea().add(widget);
dialog.run();
dialog.destroy();
GC.collect(); // Crash here

However, if I add a widget that I created manually, it works perfectly okay.
Moreover, if I change Builder#getObject(string) as follows, the problem disappears:

// gtk.Builder.d: line 779 - 789
public ObjectG getObject(string name)
{
	auto p = gtk_builder_get_object(gtkBuilder, Str.toStringz(name));

	if(p is null)
	{
		return null;
	}

	// Original line:
	//return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
	// New line:
	return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
}

Is this a bug in GtkD, and if so, is this the correct fix?

I have found that the change in Builder#getObject causes certain other issues, so it's clearly not a correct fix.
However, changing dialog.getContentArea().add(widget) to dialog.getContentArea().packStart(widget, ...) does fix the problem. Although I still find it odd that the original variant segfaults.