diff options
| -rw-r--r-- | win32/PlatWin.cxx | 16 | ||||
| -rw-r--r-- | win32/PlatWin.h | 17 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 8 | 
3 files changed, 23 insertions, 18 deletions
| diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 60bdbfee6..73f85e0a9 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -194,9 +194,7 @@ struct FormatAndMetrics {  		if (hfont)  			::DeleteObject(hfont);  #if defined(USE_D2D) -		if (pTextFormat) -			pTextFormat->Release(); -		pTextFormat = nullptr; +		ReleaseUnknown(pTextFormat);  #endif  		extraFontFlag = 0;  		characterSet = 0; @@ -1154,10 +1152,7 @@ SurfaceD2D::~SurfaceD2D() {  }  void SurfaceD2D::Clear() noexcept { -	if (pBrush) { -		pBrush->Release(); -		pBrush = nullptr; -	} +	ReleaseUnknown(pBrush);  	if (pRenderTarget) {  		while (clipsActive) {  			pRenderTarget->PopAxisAlignedClip(); @@ -1165,7 +1160,7 @@ void SurfaceD2D::Clear() noexcept {  		}  		if (ownRenderTarget) {  			pRenderTarget->EndDraw(); -			pRenderTarget->Release(); +			ReleaseUnknown(pRenderTarget);  			ownRenderTarget = false;  		}  		pRenderTarget = nullptr; @@ -1788,10 +1783,7 @@ ScreenLineLayout::ScreenLineLayout(const IScreenLine *screenLine) {  }  ScreenLineLayout::~ScreenLineLayout() { -	if (textLayout) { -		textLayout->Release(); -		textLayout = nullptr; -	} +	ReleaseUnknown(textLayout);  }  // Get the position from the provided x diff --git a/win32/PlatWin.h b/win32/PlatWin.h index 58ba5e78f..0d1c99b48 100644 --- a/win32/PlatWin.h +++ b/win32/PlatWin.h @@ -57,6 +57,23 @@ T DLLFunction(HMODULE hModule, LPCSTR lpProcName) noexcept {  	return fp;  } +// Release an IUnknown* and set to nullptr. +// While IUnknown::Release must be noexcept, it isn't marked as such so produces +// warnings which are avoided by the catch. +template <class T> +void ReleaseUnknown(T *&ppUnknown) noexcept { +	if (ppUnknown) { +		try { +			ppUnknown->Release(); +		} +		catch (...) { +			// Never occurs +		} +		ppUnknown = nullptr; +	} +} + +  UINT DpiForWindow(WindowID wid) noexcept;  int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 916185569..38fa351c0 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -678,10 +678,7 @@ void ScintillaWin::EnsureRenderTarget(HDC hdc) {  }  void ScintillaWin::DropRenderTarget() { -	if (pRenderTarget) { -		pRenderTarget->Release(); -		pRenderTarget = nullptr; -	} +	ReleaseUnknown(pRenderTarget);  }  #endif @@ -3469,8 +3466,7 @@ LRESULT PASCAL ScintillaWin::CTWndProc(  #endif  				surfaceWindow->Release();  #if defined(USE_D2D) -				if (pCTRenderTarget) -					pCTRenderTarget->Release(); +				ReleaseUnknown(pCTRenderTarget);  #endif  				::EndPaint(hWnd, &ps);  				return 0; | 
