Setting an empty ListStore as TreeView's model causes crash when headers are visible
Steps to reproduce
- Create TreeView
- Create ListStore
- Set ListStore as TreeView's model
#include <gtk/gtk.h>
enum { COL_NAME = 0, COL_AGE, NUM_COLS };
static GtkTreeModel *create_and_fill_model(void) {
GtkListStore *store;
store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
// Uncommenting these fixes the issue:
// GtkTreeIter iter;
// gtk_list_store_append(store, &iter);
// gtk_list_store_set(store, &iter, COL_NAME, "Heinz", COL_AGE, 51, -1);
return GTK_TREE_MODEL(store);
}
static GtkWidget *create_view_and_model(void) {
GtkCellRenderer *renderer;
GtkTreeModel *model;
GtkWidget *view;
view = gtk_tree_view_new();
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(
GTK_TREE_VIEW(view), -1, "Name", renderer, "text", COL_NAME, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(
GTK_TREE_VIEW(view), -1, "Age", renderer, "text", COL_AGE, NULL);
model = create_and_fill_model();
// Alternatively, uncommenting this also fixes the issue:
// gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), 0);
gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
g_object_unref(model);
return view;
}
int main(int argc, char **argv) {
GtkWidget *window;
GtkWidget *view;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
view = create_view_and_model();
gtk_container_add(GTK_CONTAINER(window), view);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Current behavior
$ gcc gtk_treeview.c `pkg-config --cflags --libs gtk+-3.0` ; ./a.exe
Assertion failed!
Program: D:\Code\gtk-treeview-c\a.exe
File: ../../cairo-1.15.12/src/cairo-surface.c, Line 542
Expected outcome
Working app.
Version information
$ pkg-config --cflags --libs gtk+-3.0
-mms-bitfields -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/fribidi -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -LC:/msys64/mingw64/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lfribidi -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
PS C:\Users\quux> systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List
OS Name : Microsoft Windows 10 Pro
OS Version : 10.0.17134 N/A Build 17134
OS Manufacturer : Microsoft Corporation
OS Configuration : Standalone Workstation
OS Build Type : Multiprocessor Free
System Boot Time : 13-Sep-18, 07:33:57
System Manufacturer : Prime
System Model : PrimePC Pro80
System Type : x64-based PC
System Directory : C:\WINDOWS\system32
System Locale : ru;Russian
Hotfix(s) : 3 Hotfix(s) Installed.,[01]: KB4230204,[02]: KB4287903,[03]: KB4343909
Edited by Ghost User