Gtk.CustomLayout segmentation fault

import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk

class Widget(Gtk.Widget):
  def __init__(self):
    super().__init__()
    def request_mode(*_):
      return Gtk.SizeRequestMode.CONSTANT_SIZE
    def measure(*_):
      return 0, 0, 0, 0
    def allocate(*_):
      pass
    self.set_layout_manager(Gtk.CustomLayout.new(request_mode, measure, allocate))

class Application(Gtk.Application):
  def do_activate(self):
    window = Gtk.ApplicationWindow(application=self)
    window.set_child(Widget())
    window.present()

Application(application_id='com.example.CustomLayout').run()

The minimal reproducible example above crashes due to a “Segmentation fault” (or even an “Illegal instruction” sometimes) on both GTK 4.8.3 (Debian Stable) and 4.16.12 (Debian Testing). Am I doing something wrong or is this indeed a bug in PyGObject as I think it is?

Never use CustomLayout in languages that are not C. It’s a convenience class for porting GTK3 containers written in C to layout managers.

Subclass GtkLayoutManager directly, and override the various virtual functions, instead; creating derived types in Python is a lot simpler.

1 Like

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