From 37c8fa161a221a263bb439a1158ba401c0cf90a3 Mon Sep 17 00:00:00 2001 From: fxliang Date: Tue, 19 Nov 2024 22:36:21 +0800 Subject: [PATCH] fix: candidate ui can't be drawn correctly after GPU reset --- WeaselUI/WeaselPanel.cpp | 11 ++++++----- include/WeaselUI.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WeaselUI/WeaselPanel.cpp b/WeaselUI/WeaselPanel.cpp index c06bedc3f..636824cf4 100644 --- a/WeaselUI/WeaselPanel.cpp +++ b/WeaselUI/WeaselPanel.cpp @@ -179,10 +179,8 @@ void WeaselPanel::_InitFontRes(bool forced) { // if style changed, or dpi changed, or pDWR NULL, re-initialize directwrite // resources if (forced || (pDWR == NULL) || (m_ostyle != m_style) || (dpiX != dpi)) { - if (pDWR) - pDWR->InitResources(m_style, dpiX); - else - pDWR = std::make_shared(m_style, dpiX); + pDWR.reset(); + pDWR = std::make_shared(m_style, dpiX); pDWR->pRenderTarget->SetTextAntialiasMode( (D2D1_TEXT_ANTIALIAS_MODE)m_style.antialias_mode); } @@ -1023,7 +1021,10 @@ void WeaselPanel::DoPaint(CDCHandle dc) { // draw candidates string if (m_candidateCount) drawn |= _DrawCandidates(memDC); - pDWR->pRenderTarget->EndDraw(); + if (FAILED(pDWR->pRenderTarget->EndDraw())) { + _InitFontRes(true); + Refresh(); + } // end texts drawing // status icon (I guess Metro IME stole my idea :) diff --git a/include/WeaselUI.h b/include/WeaselUI.h index 9a5382a69..fabe636c8 100644 --- a/include/WeaselUI.h +++ b/include/WeaselUI.h @@ -144,7 +144,8 @@ class DirectWriteResources { D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT); } HRESULT CreateBrush(const D2D1_COLOR_F& color) { - return pRenderTarget->CreateSolidColorBrush(color, pBrush.GetAddressOf()); + return pRenderTarget->CreateSolidColorBrush( + color, pBrush.ReleaseAndGetAddressOf()); } void ResetLayout() { pTextLayout.Reset(); } void SetBrushColor(const D2D1_COLOR_F& color) { pBrush->SetColor(color); }