diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-07-12 10:22:33 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-07-27 08:25:57 +0200 |
commit | 5906980ed16d99a2872a7b90c9a55dc339430f63 (patch) | |
tree | f3abcae1f5b057ffe4987ec1f9bee712300b1acd | |
parent | 971a82bab0cd1381fc5623c2ead3e72580c5006f (diff) |
tdf#118377 Do not use disposed OutputDevice
Change-Id: I7e085f69ce18e8e3c47fde690a939948454d4d15
Reviewed-on: https://gerrit.libreoffice.org/57319
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
(cherry picked from commit 3debc8c6eded517f7401c2e7ad45f73854c32e57)
Reviewed-on: https://gerrit.libreoffice.org/57581
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
Tested-by: Xisco Faulí <xiscofauli@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | vcl/source/control/ctrl.cxx | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index 8febfb02975d..775e6aa1c51c 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -385,6 +385,20 @@ void Control::SetReferenceDevice( OutputDevice* _referenceDevice ) OutputDevice* Control::GetReferenceDevice() const { + // tdf#118377 It can happen that mpReferenceDevice is already disposed and + // stays disposed (see task, even when Dialog is closed). I have no idea if + // this may be very bad - someone who knows more about lifetime of OutputDevice's + // will have to decide. + // To secure this, I changed all accesses to mpControlData->mpReferenceDevice to + // use Control::GetReferenceDevice() - only use mpControlData->mpReferenceDevice + // inside Control::SetReferenceDevice and Control::GetReferenceDevice(). + // Control::GetReferenceDevice() will now reset mpReferenceDevice if it is already + // disposed. This way all usages will do a kind of 'test-and-get' call. + if(nullptr != mpControlData->mpReferenceDevice && mpControlData->mpReferenceDevice->isDisposed()) + { + const_cast<Control*>(this)->SetReferenceDevice(nullptr); + } + return mpControlData->mpReferenceDevice; } @@ -428,14 +442,14 @@ tools::Rectangle Control::DrawControlText( OutputDevice& _rTargetDevice, const t nPStyle &= ~DrawTextFlags::HideMnemonic; } - if ( !mpControlData->mpReferenceDevice || ( mpControlData->mpReferenceDevice == &_rTargetDevice ) ) + if( !GetReferenceDevice() || ( GetReferenceDevice() == &_rTargetDevice ) ) { const tools::Rectangle aRet = _rTargetDevice.GetTextRect(rRect, rPStr, nPStyle); _rTargetDevice.DrawText(aRet, rPStr, nPStyle, _pVector, _pDisplayText); return aRet; } - ControlTextRenderer aRenderer( *this, _rTargetDevice, *mpControlData->mpReferenceDevice ); + ControlTextRenderer aRenderer( *this, _rTargetDevice, *GetReferenceDevice() ); return aRenderer.DrawText(rRect, rPStr, nPStyle, _pVector, _pDisplayText, i_pDeviceSize); } @@ -454,7 +468,7 @@ tools::Rectangle Control::GetControlTextRect( OutputDevice& _rTargetDevice, cons nPStyle &= ~DrawTextFlags::HideMnemonic; } - if ( !mpControlData->mpReferenceDevice || ( mpControlData->mpReferenceDevice == &_rTargetDevice ) ) + if ( !GetReferenceDevice() || ( GetReferenceDevice() == &_rTargetDevice ) ) { tools::Rectangle aRet = _rTargetDevice.GetTextRect( rRect, rPStr, nPStyle ); if (o_pDeviceSize) @@ -464,7 +478,7 @@ tools::Rectangle Control::GetControlTextRect( OutputDevice& _rTargetDevice, cons return aRet; } - ControlTextRenderer aRenderer( *this, _rTargetDevice, *mpControlData->mpReferenceDevice ); + ControlTextRenderer aRenderer( *this, _rTargetDevice, *GetReferenceDevice() ); return aRenderer.GetTextRect(rRect, rPStr, nPStyle, o_pDeviceSize); } |