Skip to content

Commit 8de60c8

Browse files
committed
Ensure we don't crash when checking for cancelling print job
Don't dereference sm_abortWindow without checking that it is non-null in wxAbortProc(): even though it's not supposed to happen, it still somehow does, apparently, so just log a debug message instead of crashing in this case. See wxWidgets#23927. (cherry picked from commit 9a72819)
1 parent 0efe1b7 commit 8de60c8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

docs/changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ wxMSW:
324324
- Fix wrong wxWindowsPrintNativeData initialization (Stefan Ziegler, #23685).
325325
- Fix position of wxStaticBox label after DPI change (Maarten Bent, #23740).
326326
- Fix background colour of empty cells in wxDataViewCtrl (#23708).
327+
- Fix possible (even if rare) crash in printer progress dialog (#23927).
327328

328329
wxOSX:
329330

src/msw/printwin.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,24 @@ BOOL CALLBACK wxAbortProc(HDC WXUNUSED(hdc), int WXUNUSED(error))
425425
return(TRUE);
426426

427427
/* Process messages intended for the abort dialog box */
428+
const HWND hwnd = GetHwndOf(wxPrinterBase::sm_abortWindow);
428429

429430
while (!wxPrinterBase::sm_abortIt && ::PeekMessage(&msg, 0, 0, 0, TRUE))
430-
if (!IsDialogMessage((HWND) wxPrinterBase::sm_abortWindow->GetHWND(), &msg)) {
431+
{
432+
// Apparently handling the message may, somehow, result in
433+
// sm_abortWindow being destroyed, so guard against this happening.
434+
if (!wxPrinterBase::sm_abortWindow)
435+
{
436+
wxLogDebug(wxS("Print abort dialog unexpected disappeared."));
437+
return TRUE;
438+
}
439+
440+
if (!IsDialogMessage(hwnd, &msg))
441+
{
431442
TranslateMessage(&msg);
432443
DispatchMessage(&msg);
433444
}
445+
}
434446

435447
/* bAbort is TRUE (return is FALSE) if the user has aborted */
436448

0 commit comments

Comments
 (0)