diff --git a/docs/changes.txt b/docs/changes.txt index c4c1e3fd24..672760b7d9 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -324,6 +324,7 @@ wxMSW: - Fix wrong wxWindowsPrintNativeData initialization (Stefan Ziegler, #23685). - Fix position of wxStaticBox label after DPI change (Maarten Bent, #23740). - Fix background colour of empty cells in wxDataViewCtrl (#23708). +- Fix possible (even if rare) crash in printer progress dialog (#23927). wxOSX: diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index cf644d3a8f..0cd213136a 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -425,12 +425,24 @@ BOOL CALLBACK wxAbortProc(HDC WXUNUSED(hdc), int WXUNUSED(error)) return(TRUE); /* Process messages intended for the abort dialog box */ + const HWND hwnd = GetHwndOf(wxPrinterBase::sm_abortWindow); while (!wxPrinterBase::sm_abortIt && ::PeekMessage(&msg, 0, 0, 0, TRUE)) - if (!IsDialogMessage((HWND) wxPrinterBase::sm_abortWindow->GetHWND(), &msg)) { + { + // Apparently handling the message may, somehow, result in + // sm_abortWindow being destroyed, so guard against this happening. + if (!wxPrinterBase::sm_abortWindow) + { + wxLogDebug(wxS("Print abort dialog unexpected disappeared.")); + return TRUE; + } + + if (!IsDialogMessage(hwnd, &msg)) + { TranslateMessage(&msg); DispatchMessage(&msg); } + } /* bAbort is TRUE (return is FALSE) if the user has aborted */