IllegalArgumentException when painting image while running out of handles
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start in Image.java at the GetDIBits call cited in the issue, then trace how its return value reaches DestroyableImageHandle.getImageData and image painting. Reproduce on Windows with the supplied program or a focused test that exhausts handles. Done means handle exhaustion reports an SWT error such as “No more handles,” rather than an IllegalArgumentException.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Trying to paint an image while all available handles have been consumed fails with an IllegalArgumentException instead of an SWTError.
To Reproduce
package gef;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DrawGC2 {
public static void main(String[] args) {
Shell shell = new Shell();
Display display = shell.getDisplay();
int width = 310;
int height = 310;
List<Image> images = new ArrayList<>();
for (int i = 0; i < 8000; ++i) {
Image image = new Image(display, width, height);
GC gc = new GC(image);
gc.dispose();
images.add(image);
}
shell.addPaintListener(event -> {
for (Image image : images) {
event.gc.drawImage(image, 0, 0, width, height, 0, 0, 100, 100);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
images.forEach(Image::dispose);
}
}
Stacktrace:
Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid
at org.eclipse.swt.SWT.error(SWT.java:4915)
at org.eclipse.swt.SWT.error(SWT.java:4849)
at org.eclipse.swt.SWT.error(SWT.java:4820)
at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:439)
at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:287)
at org.eclipse.swt.graphics.Image$DestroyableImageHandle.getImageData(Image.java:3305)
at org.eclipse.swt.graphics.Image$AbstractImageProviderWrapper.getClosestAvailableImageData(Image.java:2106)
at org.eclipse.swt.graphics.Image$PlainImageProviderWrapper.loadImageData(Image.java:2388)
at org.eclipse.swt.graphics.Image$HandleAtSize.getOrCreateImageHandleAtClosestSize(Image.java:254)
at org.eclipse.swt.graphics.Image$HandleAtSize.lambda$0(Image.java:225)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at org.eclipse.swt.graphics.Image$HandleAtSize.refresh(Image.java:225)
at org.eclipse.swt.graphics.Image.executeOnImageHandleAtBestFittingSize(Image.java:968)
at org.eclipse.swt.graphics.GC$DrawScalingImageToImageOperation.draw(GC.java:1240)
at org.eclipse.swt.graphics.GC$DrawScalingImageToImageOperation.apply(GC.java:1222)
at org.eclipse.swt.graphics.GC.storeAndApplyOperationForExistingHandle(GC.java:6136)
at org.eclipse.swt.graphics.GC.drawImage(GC.java:1152)
at gef.DrawGC2.lambda$0(DrawGC2.java:30)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:272)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4363)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1217)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1241)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1226)
at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1627)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:5021)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:336)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1490)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2446)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5131)
at org.eclipse.swt.internal.win32.OS.UpdateWindow(Native Method)
at org.eclipse.swt.widgets.Decorations.setVisible(Decorations.java:1322)
at org.eclipse.swt.widgets.Shell.setVisible(Shell.java:2192)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1334)
at gef.DrawGC2.main(DrawGC2.java:34)
Expected behavior
SWT should return a proper error message. Ideally an "No more handles" error.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
Version since
Only tested on master.
Additional information
I think the problem is that the return value is not validated when calling GetDIBits, for example here:
From the documentation:
If the function fails, the return value is zero.
Which is the case here, resulting in an "empty" image data, causing the validation error.
- Ngôn ngữ chính
- Java
- Star
- 202
- Fork
- 206
- Merge trung bình
- 16 giờ 56 phút
- Pull request đã merge (30 ngày)
- 110
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eclipse-platform/eclipse.platform.swt
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`Có thể đã có người làm @GreenFuze đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
eclipse-platform/eclipse.platform.swt#3665 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
eclipse-platform/eclipse.platform.swt#3336 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
eclipse-platform/eclipse.platform.swt#3718 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eclipse-platform/eclipse.platform.swt
Issue tương tự
-
approved bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
checkstyle/checkstyle#21981 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
beehive-lab/TornadoVM#1248 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc-v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3214 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Java and Kotlin (JVM): parse gradle/wrapper/gradle-wrapper.properties with exact line locationsĐang mởarea: detector eco: java help wanted lane: free-agent roadmap size: S type: parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
arminazimi/evergreen#355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
micronaut-projects/micronaut-data#4134 ·
Maintainer thường phản hồi trong vòng 1 ngày