Skip to content

Commit

Permalink
#924 [Win32] Possible ERROR_GRAPHIC_DISPOSED error during painting
Browse files Browse the repository at this point in the history
This should cover the case that BeginBufferedPaint might fail.
  • Loading branch information
Thomas Singer committed Sep 3, 2024
1 parent 243f2c5 commit 8173af6
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1521,30 +1521,32 @@ LRESULT WM_PAINT (long wParam, long lParam) {
RECT prcTarget = new RECT ();
OS.SetRect (prcTarget, ps.left, ps.top, ps.right, ps.bottom);
long hBufferedPaint = OS.BeginBufferedPaint (hDC, prcTarget, flags, null, phdc);
GCData data = new GCData ();
data.device = display;
data.foreground = getForegroundPixel ();
Control control = findBackgroundControl ();
if (control == null) control = this;
data.background = control.getBackgroundPixel ();
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), nativeZoom);
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
if ((style & SWT.NO_BACKGROUND) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
//paintGC.copyArea (image, ps.left, ps.top);
} else {
RECT rect = new RECT ();
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
drawBackground (phdc [0], rect);
if (hBufferedPaint != null && phdc[0] != 0) {
GCData data = new GCData ();
data.device = display;
data.foreground = getForegroundPixel ();
Control control = findBackgroundControl ();
if (control == null) control = this;
data.background = control.getBackgroundPixel ();
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), nativeZoom);
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
if ((style & SWT.NO_BACKGROUND) != 0) {
/* This code is intentionally commented because it may be slow to copy bits from the screen */
//paintGC.copyArea (image, ps.left, ps.top);
} else {
RECT rect = new RECT ();
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
drawBackground (phdc [0], rect);
}
GC gc = createNewGC(phdc [0], data);
Event event = new Event ();
event.gc = gc;
event.setBounds(DPIUtil.scaleDown(new Rectangle(ps.left, ps.top, width, height), getZoom()));
sendEvent (SWT.Paint, event);
if (data.focusDrawn && !isDisposed ()) updateUIState ();
gc.dispose ();
OS.EndBufferedPaint (hBufferedPaint, true);
}
GC gc = createNewGC(phdc [0], data);
Event event = new Event ();
event.gc = gc;
event.setBounds(DPIUtil.scaleDown(new Rectangle(ps.left, ps.top, width, height), getZoom()));
sendEvent (SWT.Paint, event);
if (data.focusDrawn && !isDisposed ()) updateUIState ();
gc.dispose ();
OS.EndBufferedPaint (hBufferedPaint, true);
}
OS.EndPaint (handle, ps);
} else {
Expand Down

0 comments on commit 8173af6

Please sign in to comment.