-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIGSEGV in Tree.cellDataProc
when calling TreeItem.setImage
#678
Comments
Tree.cellDataProc
when calling TreeItem.setImage
Tree.cellDataProc
when calling TreeItem.setImage
Tree.cellDataProc
when calling TreeItem.setImage
Tree.cellDataProc
when calling TreeItem.setImage
Sorry about the waiting time, SWT currently has few active maintainers. |
Hello, just a ping on this issue: We are still often encountering this crash on an almost daily basis... :/ |
SWT is currently low on active contributors. |
Of course, I understand, FOSS is what it is...
Actually we ended up tossing the problematic pieces of code (in this one and #697) into a |
I found a way to reproduce all the time in a @flatpak runtime, where also all workarounds fail. |
It would be useful if you describe how exactly do you reproduce. |
Sorry, I thought that it won't be that helpful because you need to build a package to test. Here it is https://github.com/Mailaender/flathub/compare/chemclipse Check the README for the commands to build it. Click Use runtime-version: 20.08 and rebuild to see how the application looked before the crash was introduced. |
Oh, I didn't expect a whole other application. Indeed I don't have the time to debug it. |
You can also indirectly trigger this with public class MyLabelProvider extends LabelProvider implements ILabelProvider {
@Override
public Image getImage(Object element) {
// return something other then null
}
} This is sometimes difficult to reproduce. I had my best chances when there was only one unexpanded item in the tree viewer. |
We still have the |
There are occasions where the I just copied your snippet into my 2023-03 project and it crashed. It does not when I try it here. The instructions at https://www.eclipse.org/swt/git.php are somehow outdated or not very precise, but this should work: Install
I just ignored the API baseline error and got a test environment where the problem is not reproducible or hopefully already fixed. |
Updated consecutively up to Eclipse 2023-12 and the crash is still there. |
While trying to work around it, I found another way to crash more reliable: public class MyLabelProvider extends LabelProvider implements ILabelProvider {
@Override
public Image getImage(Object element) {
try {
Thread.sleep(100);
} catch(InterruptedException e) {
logger.warn(e);
}
new Image(display, 16, 16))
}
} |
I have no real fix yet, and the |
I also don't understand why this crash does not happen with the Eclipse IDE. The PDE Project Explorer and Java Package Explorer as well as the Git Repositories all use trees with icons. |
The crash happens when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
GTK 3.24.41 (Ubuntu 24) crashes when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
GTK 3.24.41 (Ubuntu 24) crashes when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
@ericwill why does TreeItem.setImage() recreate renderer for a single column? Should not all columns be affected? |
@SyntevoAlex could you please suggest a way to detect GTK warnings from Junit tests? GTK has been desperately trying to warn us about this problem, but we always ignore its printout to standard error:
|
You're asking me about code I haven't touched in ~4 years, so I might be wrong. If memory serves correctly the method in question modifies only one column at a time as per SWT API. Also the method in question involves |
It was trying to solve cropping of images by using actual size in This is fine, neither of us probably have time to write a test anyway 🤷 |
The enhaced reproducer with a fixed SWT version can now be found in https://github.com/basilevs/bug_678 |
GTK 3.24.41 (Ubuntu 24) crashes when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
GTK 3.24.41 (Ubuntu 24) crashes when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
GTK 3.24.41 (Ubuntu 24) crashes when renderers are replaced during render. If replacement is postponed, the crash no longer happens. Fixes eclipse-platform#678.
It tried adding package swt_tree_crash;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class Main {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(400, 300);
shell.setLayout(new FillLayout());
Tree tree = new Tree(shell, SWT.VIRTUAL);
tree.addListener(SWT.SetData, new Listener() {
public void handleEvent(final Event e) {
TreeItem item = (TreeItem)e.item;
item.setText(0, "A");
try {
Thread.sleep(1000);
}
catch ( InterruptedException ex ) {
throw new RuntimeException(ex);
}
item.setImage(new Image(display, 20, 20)); // <-- this is the critical line!
}
});
tree.setItemCount(1);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
} |
@om-11-2024 does wrapping |
Yes, this fixes the bug in the snippet. |
Here is what causes the error in the swt code. The problem is inside Here is the stacktrace to
Here is the problem in @Override
long cellDataProc (long tree_column, long cell, long tree_model, long iter, long data) {
...
boolean setData = false;
...
if ((style & SWT.VIRTUAL) != 0) {
...
setData = checkData (item); // <= HERE new renderers are created, and the current renderer is disposed + it's memory is freed
...
}
...
long [] ptr = new long [1];
if (setData) {
...
GTK.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1);
if (ptr [0] != 0) {
OS.g_object_set (cell, OS.text, ptr[0], 0); // <= HERE is an attempt to set property for the already disposed current renderer
OS.g_free (ptr[0]);
}
}
} The problem is that:
Here is how the current renderer is released inside
|
Because Initially at the beginning of Later in By the time we get to |
@om-11-2024 I assumed renderers are reference-counted, so cell object should hold its own reference to renderer, preventing the disposal. Could you send a link to GTK code managing cell object? |
Sure, here are some links:
And here is native stacktrace for g_object_unref() at gobject.c:4 381 0x731907fb46d0
cell_info_free() at gtkcellareabox.c:412 0x731905725e8c
gtk_cell_area_box_remove() at gtkcellareabox.c:1 121 0x7319057277bb
gtk_cell_area_remove() at gtkcellarea.c:1 671 0x73190571e8d4
gtk_cell_area_clear() at gtkcellarea.c:1 502 0x73190571e263
gtk_cell_layout_clear() at gtkcelllayout.c:415 0x73190572e1eb
gtk_cell_layout_default_clear() at gtkcelllayout.c:236 0x73190572d9d8
gtk_cell_layout_clear() at gtkcelllayout.c:415 0x73190572e1eb
gtk_tree_view_column_clear() at gtktreeviewcolumn.c:1 693 0x731905ac6f2e
Java_org_eclipse_swt_internal_gtk_GTK_gtk_1tree_1view_1column_1clear() at 0x731906047569 This stacktrace is also for this snippet Inside this So yes, the renderer is reference-counted, its owner is column. |
@om-11-2024 do you think Tree.cellDataProc is called from apply_cell_attributes? |
It is. Here is the stacktrace with both
Agree.
Maybe.
I'm not a fan of the fact that #1612 adds asynchronicity to |
Indexing options for further discussion:
|
Yes, it's 480261, not 513761. |
…latform#678 Fix and test for bug eclipse-platform#678 Fixes eclipse-platform#678 Reproducing the crash: - eclipse-platform#678 (comment) - eclipse-platform#1611 - eclipse-platform#678 (comment) The cause of the crash is described here: eclipse-platform#678 (comment) In short, the problem was executing `Tree.createRenderers()` inside `TreeItem.setImage()`. The sequence of action leading to the crash was: in a `Tree` with `SWT.VIRTUAL` a `TreeItem` is rendered for the first time or after `clear()` `Tree.cellDataProc()` is executed for the item and one of it's renderers `Tree.checkData(item)` is called for the item `SWT.SetData` is invoked and executes `TreeItem.setImage()` `Tree.createRenderers()` executes and disposes the current renderer further actions in `Tree.cellDataProc()` that access the already-disposed renderer (they think it's alive) How it's fixed: 1. set fixed height+width to pixbuf renderers with `GTK.gtk_cell_renderer_set_fixed_size` This does 2 things: - from now on it makes images rendered by the renderer to be rendered with these height+width - from now on fixed row height calculation will return height of at least fixed height of the pixbuf 2. make `GtkTreeView` recompute it's internally stored fixed row height with re-setting `fixed_height_mode` of the GtkTreeView 3. make all existing tree rows update their height by invoking `gtk_tree_view_row_changed()` on each of the rows. (2) and (3) can also be achieved by creating a copy of the current `GtkTreeModel` and assigning it to the `GtkTreeView`. But this also resets current selected rows, focus and scroll position; that's why I chose re-setting `fixed_height_mode` + `gtk_tree_view_row_changed()` instead.
…latform#678 Fix and test for bug eclipse-platform#678 Fixes eclipse-platform#678 Reproducing the crash: - eclipse-platform#678 (comment) - eclipse-platform#1611 - eclipse-platform#678 (comment) The cause of the crash is described here: eclipse-platform#678 (comment) In short, the problem was executing `Tree.createRenderers()` inside `TreeItem.setImage()`. The sequence of action leading to the crash was: in a `Tree` with `SWT.VIRTUAL` a `TreeItem` is rendered for the first time or after `clear()` `Tree.cellDataProc()` is executed for the item and one of it's renderers `Tree.checkData(item)` is called for the item `SWT.SetData` is invoked and executes `TreeItem.setImage()` `Tree.createRenderers()` executes and disposes the current renderer further actions in `Tree.cellDataProc()` that access the already-disposed renderer (they think it's alive) How it's fixed: 1. set fixed height+width to pixbuf renderers with `GTK.gtk_cell_renderer_set_fixed_size` This does 2 things: - from now on it makes images rendered by the renderer to be rendered with these height+width - from now on fixed row height calculation will return height of at least fixed height of the pixbuf 2. make `GtkTreeView` recompute it's internally stored fixed row height with re-setting `fixed_height_mode` of the GtkTreeView 3. make all existing tree rows update their height by invoking `gtk_tree_view_row_changed()` on each of the rows. (2) and (3) can also be achieved by creating a copy of the current `GtkTreeModel` and assigning it to the `GtkTreeView`. But this also resets current selected rows, focus and scroll position; that's why I chose re-setting `fixed_height_mode` + `gtk_tree_view_row_changed()` instead.
I looked into the code of swt and gtk here is what I found out:
The fixed row row height for a So basically what we need to do is: when the 1st image is inserted to the tree, we need to:
I found 2 ways to do that in gtk code:
I chose option 2 in #1662 simply because it doesn't resets current selection, focus and scroll position for the tree. P.S. It turns out that using |
Describe the bug
Virtual
Tree
widget crashes JVM (through GTK3) when settingImage
ontoTreeItem
inListener
toSWT.SetData
.This is a continuation of https://bugs.eclipse.org/bugs/show_bug.cgi?id=573090.
To Reproduce
Expected behavior
The application always shows a window with a tree widget in it, containing one item, with a small white icon.
Screenshots
Not applicable.
Environment:
Operating System: Fedora Linux 38
KDE Plasma Version: 5.27.4
KDE Frameworks Version: 5.105.0
Qt Version: 5.15.9
Kernel Version: 6.2.15-300.fc38.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 3800X 8-Core Processor
Memory: 31.2 GiB of RAM
Graphics Processor: AMD Radeon RX 550 Series
org.eclipse.swt.internal.gtk.version=3.24.37
JRE version: OpenJDK Runtime Environment Temurin-17.0.7+7 (17.0.7+7) (build 17.0.7+7)
Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (17.0.7+7, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
Version since
Tested on Eclipse 4.27 (SWT 4.958).
Workaround (or) Additional context
The crash doesn't always happen, but fairly often.
Removing the
TreeItem.setImage
call avoids the crash entirely.The text was updated successfully, but these errors were encountered: