[Bug?] Strange size allocation warnings with GtkPopoverMenuBar


I recently updated my installation of GTK4 (from the git sources, to version 4.5.1) and found that the app I am developing suddenly has warnings of the form:

(main:147097): Gtk-CRITICAL **: 03:47:57.632: gtk_widget_measure: assertion 'for_size >= -1' failed
(main:147097): Gtk-CRITICAL **: 03:47:57.635: gtk_widget_measure: assertion 'for_size >= minimum opposite size' failed: 170 >= 851

I have been trying to find and fix whatever mistake I have made to cause these messages, but I have found the process confusing and I am at a stage where I am very unsure as to why I am seeing certain behaviour. I did however find that the errors disappeared if the GtkPopoverMenuBar in the application was not rendered.

I have a minimal example to reproduce this behaviour:
This should just create a GtkApplicationWindow containing a button and a GtkPopoverMenuBar initialised from a GMenuModel created using a GtkBuilder from a GResource, and yet I am seeing errors.


#include <gtk/gtk.h>
#include <stdio.h>

static void activate(GApplication *app, gpointer user_data)
        GtkWidget *win = gtk_application_window_new(GTK_APPLICATION(app));
        gtk_window_set_default_size(GTK_WINDOW(win), 200, 200);

        GtkWidget *btn = gtk_button_new_with_label("hello");
        gtk_window_set_child(GTK_WINDOW(win), btn);

        GtkBuilder *builder = gtk_builder_new_from_resource("/menu.ui");
        GMenuModel *model = G_MENU_MODEL(gtk_builder_get_object(builder, "menubar"));
        gtk_application_set_menubar(GTK_APPLICATION(app), model);

        gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(win), TRUE);


int main(int argc, char *argv[])
        GtkApplication *app = gtk_application_new("com.test", G_APPLICATION_FLAGS_NONE);
        g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
        int status = g_application_run(G_APPLICATION(app), argc, argv);
        return status;


<?xml version="1.0" encoding="UTF-8"?>
  <gresource prefix="/">
    <file compressed="true" preprocess="xml-stripblanks" alias="menu.ui">menu.ui</file>


<?xml version="1.0" encoding="UTF-8"?>
  <requires lib="gtk" version="4.0"/>
  <menu id="menubar">
      <attribute name="label" translatable="yes">_File</attribute>
          <attribute name="label" translatable="yes">_New</attribute>

I am compiling this with

$ glib-compile-resources --generate-source --target=resources.c program.gresource.xml
$ clang -o main main.c resources.c `pkg-config --cflags --libs gtk4`

When I run this with ./main I see

(main:152320): Gtk-CRITICAL **: 04:07:28.229: gtk_widget_measure: assertion 'for_size >= -1' failed

Can someone explain what I am doing wrong? Or is this not the intended behaviour of GTK?

Many thanks in advance!

Neither, probably just a bug in GTK.

It’d be great not to have these errors though if it’s not something I’ve done wrong.
Personally I would not know where to start trying to write a fix for GTK; is there anyone who I can talk to who would be able to fix this?

Hello again,

After a commit (de42b5bfae8d74d0de1f66f9095eef5969b4e8b1, see more at https://gitlab.gnome.org/GNOME/gtk/-/commit/de42b5bfae8d74d0de1f66f9095eef5969b4e8b1) one of the errors I was seeing has been removed (seemingly as a temporary fix though).

Specifically, I was seeing

(main:147097): Gtk-CRITICAL **: 03:47:57.632: gtk_widget_measure: assertion 'for_size >= -1' failed
(main:147097): Gtk-CRITICAL **: 03:47:57.635: gtk_widget_measure: assertion 'for_size >= minimum opposite size' failed: 170 >= 851

But I now only see

(main:147097): Gtk-CRITICAL **: 03:47:57.632: gtk_widget_measure: assertion 'for_size >= -1' failed

However this error is still confusing to me and actually is the only one I was seeing with my minimal example. The commit mentions that GtkGrids were causing the error which has now been removed; since I was using GtkGrids in my program I guess that’s why one error has disappeared.
But I am still seeing a strange error that seems to be caused by the GtkPopoverMenuBar and which I do not think should be present.

Hopefully someone can advise?


Write a minimal reproducer and open a bug report on gitlab. If you can’t write a minimal reproducer, it’s likely caused by something else you do in your application.

The minimal example is in the first post…

I have now opened a bug report, so I suppose further conversation will be at https://gitlab.gnome.org/GNOME/gtk/-/issues/4569.

Thanks for your time!

As was stated in the gitlab issue, the issue seems to have been fixed!

Thanks all for your time.