Hello,
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.
main.c:
#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);
g_object_unref(builder);
gtk_application_window_set_show_menubar(GTK_APPLICATION_WINDOW(win), TRUE);
gtk_widget_show(win);
}
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);
g_object_unref(app);
return status;
}
program.gresource.xml:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/">
<file compressed="true" preprocess="xml-stripblanks" alias="menu.ui">menu.ui</file>
</gresource>
</gresources>
menu.ui:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<menu id="menubar">
<submenu>
<attribute name="label" translatable="yes">_File</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_New</attribute>
</item>
</section>
</submenu>
</menu>
</interface>
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!