Skip to content

Commit 485f9db

Browse files
Thomas SingerHeikoKlare
authored andcommitted
#924 [Win32] Possible ERROR_GRAPHIC_DISPOSED error during painting
This should cover the case that BeginBufferedPaint might fail.
1 parent 2ce8542 commit 485f9db

File tree

1 file changed

+25
-23
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+25
-23
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,30 +1521,32 @@ LRESULT WM_PAINT (long wParam, long lParam) {
15211521
RECT prcTarget = new RECT ();
15221522
OS.SetRect (prcTarget, ps.left, ps.top, ps.right, ps.bottom);
15231523
long hBufferedPaint = OS.BeginBufferedPaint (hDC, prcTarget, flags, null, phdc);
1524-
GCData data = new GCData ();
1525-
data.device = display;
1526-
data.foreground = getForegroundPixel ();
1527-
Control control = findBackgroundControl ();
1528-
if (control == null) control = this;
1529-
data.background = control.getBackgroundPixel ();
1530-
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), nativeZoom);
1531-
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
1532-
if ((style & SWT.NO_BACKGROUND) != 0) {
1533-
/* This code is intentionally commented because it may be slow to copy bits from the screen */
1534-
//paintGC.copyArea (image, ps.left, ps.top);
1535-
} else {
1536-
RECT rect = new RECT ();
1537-
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
1538-
drawBackground (phdc [0], rect);
1524+
if (hBufferedPaint != 0 && phdc[0] != 0) {
1525+
GCData data = new GCData ();
1526+
data.device = display;
1527+
data.foreground = getForegroundPixel ();
1528+
Control control = findBackgroundControl ();
1529+
if (control == null) control = this;
1530+
data.background = control.getBackgroundPixel ();
1531+
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), nativeZoom);
1532+
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
1533+
if ((style & SWT.NO_BACKGROUND) != 0) {
1534+
/* This code is intentionally commented because it may be slow to copy bits from the screen */
1535+
//paintGC.copyArea (image, ps.left, ps.top);
1536+
} else {
1537+
RECT rect = new RECT ();
1538+
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
1539+
drawBackground (phdc [0], rect);
1540+
}
1541+
GC gc = createNewGC(phdc [0], data);
1542+
Event event = new Event ();
1543+
event.gc = gc;
1544+
event.setBounds(DPIUtil.scaleDown(new Rectangle(ps.left, ps.top, width, height), getZoom()));
1545+
sendEvent (SWT.Paint, event);
1546+
if (data.focusDrawn && !isDisposed ()) updateUIState ();
1547+
gc.dispose ();
1548+
OS.EndBufferedPaint (hBufferedPaint, true);
15391549
}
1540-
GC gc = createNewGC(phdc [0], data);
1541-
Event event = new Event ();
1542-
event.gc = gc;
1543-
event.setBounds(DPIUtil.scaleDown(new Rectangle(ps.left, ps.top, width, height), getZoom()));
1544-
sendEvent (SWT.Paint, event);
1545-
if (data.focusDrawn && !isDisposed ()) updateUIState ();
1546-
gc.dispose ();
1547-
OS.EndBufferedPaint (hBufferedPaint, true);
15481550
}
15491551
OS.EndPaint (handle, ps);
15501552
} else {

0 commit comments

Comments
 (0)