Skip to content

Commit 81a811a

Browse files
committed
[Gtk3] Fix crash in TreeItem.setImage
Calling createRenderers() (which invokes gtk_tree_view_column_clear()) is unsafe when setImage() call originates from a SWT.SetData listener, because GTK is currently iterating the column's cell renderer list inside gtk_tree_view_column_cell_set_cell_data(). This frees that list while GTK still holds a pointer into it, causing a use-after-free SIGSEGV on GTK3 (#678 ). Instead, toggle the fixed-height-mode GObject property off and back on. This resets GTK's cached row height (fixed_height = -1) and schedules an async widget resize, so GTK will re-measure on the next layout pass and pick up the updated renderer size. Unlike gtk_tree_view_column_clear(), this does not modify the renderer list and is therefore safe to call from within a cell_data_func callback. Tested that Debug and variable views don't have icons without the fixed_height_mode off/on setting and icons are fine with it.
1 parent 88efa82 commit 81a811a

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

  • bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1516,18 +1516,20 @@ public void setImage(int index, Image image) {
15161516
* Feature in GTK: a Tree with the style SWT.VIRTUAL has
15171517
* fixed-height-mode enabled. This will limit the size of
15181518
* any cells, including renderers. In order to prevent
1519-
* images from disappearing/being cropped, we re-create
1520-
* the renderers when the first image is set. Fix for
1519+
* images from disappearing/being cropped, GTK's cached
1520+
* row height must be invalidated so it re-measures with
1521+
* the new pixbuf renderer size (set above). Fix for
15211522
* bug 480261.
1523+
*
1524+
* Toggle the fixed-height-mode GObject property
1525+
* off and back on. This resets GTK's cached row height
1526+
* (fixed_height = -1) and schedules an async widget resize,
1527+
* so GTK will re-measure on the next layout pass and pick
1528+
* up the updated renderer size.
15221529
*/
15231530
if ((parent.style & SWT.VIRTUAL) != 0) {
1524-
/*
1525-
* Only re-create SWT.CHECK renderers if this is the first column.
1526-
* Otherwise check-boxes will be rendered in columns they are not
1527-
* supposed to be rendered in. See bug 513761.
1528-
*/
1529-
boolean check = modelIndex == Tree.FIRST_COLUMN && (parent.style & SWT.CHECK) != 0;
1530-
parent.createRenderers(column, modelIndex, check, parent.style);
1531+
OS.g_object_set(parent.handle, OS.fixed_height_mode, false, 0);
1532+
OS.g_object_set(parent.handle, OS.fixed_height_mode, true, 0);
15311533
}
15321534
}
15331535
}

0 commit comments

Comments
 (0)