Skip to content

Commit

Permalink
fix: candidate ui can't be drawn correctly after GPU reset
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Nov 20, 2024
1 parent 0ef3154 commit ddff9a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DirectWriteResources>(m_style, dpiX);
pDWR.reset();
pDWR = std::make_shared<DirectWriteResources>(m_style, dpiX);
pDWR->pRenderTarget->SetTextAntialiasMode(
(D2D1_TEXT_ANTIALIAS_MODE)m_style.antialias_mode);
}
Expand Down Expand Up @@ -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 :)
Expand Down
3 changes: 2 additions & 1 deletion include/WeaselUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down

0 comments on commit ddff9a0

Please sign in to comment.