Possibly there is a bug in the GTK caller of GtkLayoutManagerClass->measure()

Still experimenting and polishing my flow widget…

While doing that I found that there might be a bug in the GTK libraries and my GtkLayoutManagerClass->measure() function sometimes is invoked with weird values in the for_size parameter. It looks like the GTK caller caches some random value and keeps adding numbers to it unbounded.

The “returned value” that I print in the terminal is what my function yields in return (I set the *minimum and *natural pointers to the same value, the one that I print).

possibly_a_bug

Basically my GtkLayoutManagerClass->measure() function the example above ends like this:

...

printf(
	"Orientation: %s, for size: %d, returned value: %d\n",
	dimension == GTK_ORIENTATION_VERTICAL ?
		"VERTICAL"
	:
		"HORIZONTAL",
	for_size,
	ret_min
);

if (minimum) {

	*minimum = ret_min;

}

if (natural) {

	*natural = ret_min;

}

―madmurphy

EDIT If I am not wrong I suspect that the bug might come from the gtk_widget_query_size_for_orientation() function of gtk/gtksizerequest.c.

I still cannot figure out what is going on.

The problem is the following. When my layout is in horizontal orientation it is in GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode, and my GtkLayoutManagerClass->measure() function is invoked repeatedly with different parameters according to the mode.

For unknown reasons, the gtk_widget_query_size_for_orientation() function from gtk/gtksizerequest.c keeps asking for the height for a larger and larger width, and so my my layout correctly responds by measuring the tallest between all its children and returning that value. Indeed, that is the height that the flow widget would have if all its children were positioned along a very wide single line. In the animated GIF from my previous message the tallest child is 32 pixel tall, and so my flow widget returns 32.

But here comes the problem. The real width is much smaller, and that leads to a taller height. Yet, if I try to downsize the window, I am not stopped until I reach the height of 32 pixels, and that is because my measure() function is asked “How tall would you be if your were 1000px large (or so)?”. But nothing is 1000px large here…

You can see in the following screencast what happens when I try to downsize the window:

what-is-happening

Obviously the downsizing should be prevented earlier.

I have checked, and I am pretty sure that my measure() function yields the right height when it is given the right width. The problem is that the GTK caller wants to know the height for a much wider width that keeps increasing the more I add children.

―madmurphy

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