From 5c3ddb7a7f56e18f890504b46b37addba00c70b2 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Thu, 20 Dec 2018 13:41:02 +0000 Subject: [PATCH] Prevent crash when attempting to clear a DC with not device under wxQT --- src/qt/dc.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index e5405276cd..5cd918ba2c 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -115,14 +115,46 @@ bool wxQtDCImpl::CanGetTextExtent() const void wxQtDCImpl::DoGetSize(int *width, int *height) const { - if (width) *width = m_qtPainter->device()->width(); - if (height) *height = m_qtPainter->device()->height(); + QPaintDevice *pDevice = m_qtPainter->device(); + + int deviceWidth; + int deviceHeight; + + if (pDevice) + { + deviceWidth = pDevice->width(); + deviceHeight = pDevice->height(); + } + else + { + deviceWidth = 0; + deviceHeight = 0; + + } + if (width) *width = deviceWidth; + if (height) *height = deviceHeight; } void wxQtDCImpl::DoGetSizeMM(int* width, int* height) const { - if (width) *width = m_qtPainter->device()->widthMM(); - if (height) *height = m_qtPainter->device()->heightMM(); + QPaintDevice *pDevice = m_qtPainter->device(); + + int deviceWidthMM; + int deviceHeightMM; + + if (pDevice) + { + deviceWidthMM = pDevice->widthMM(); + deviceHeightMM = pDevice->heightMM(); + } + else + { + deviceWidthMM = 0; + deviceHeightMM = 0; + } + + if (width) *width = deviceWidthMM; + if (height) *height = deviceHeightMM; } int wxQtDCImpl::GetDepth() const