Crashes if zoom font size up and down rapidly with ctrl + scroll wheel #7568

Closed
opened 2026-01-31 01:07:29 +00:00 by claunia · 2 comments
Owner

Originally created by @guyrleech on GitHub (Apr 23, 2020).

Originally assigned to: @leonMSFT on GitHub.

Environment

Win10 1909 x64

Windows Terminal version (if applicable): 0.11.1121.0

Steps to reproduce

Increase and decrease the font size rapidly in the first tab using ctrl and mouse scroll wheel

Expected behavior

Not to crash

Actual behavior

Crashes


Crashes every time when I use Ctrl and the mouse wheel to increase and decrease the font rapidly. Only happens with the first tab and regardless of what is running in there. I have crash dumps. Doesn't crash when I try and record a video of it in Snagit.

image

Originally created by @guyrleech on GitHub (Apr 23, 2020). Originally assigned to: @leonMSFT on GitHub. # Environment Win10 1909 x64 Windows Terminal version (if applicable): 0.11.1121.0 # Steps to reproduce Increase and decrease the font size rapidly in the first tab using ctrl and mouse scroll wheel # Expected behavior Not to crash # Actual behavior Crashes --- Crashes every time when I use Ctrl and the mouse wheel to increase and decrease the font rapidly. Only happens with the first tab and regardless of what is running in there. I have crash dumps. Doesn't crash when I try and record a video of it in Snagit. ![image](https://user-images.githubusercontent.com/11651939/80043624-22dfbc80-84fa-11ea-8725-1b62874966cf.png)
Author
Owner

@skyline75489 commented on GitHub (Apr 27, 2020):

It's very easy to reproduce this crash with Release build. The root cause I think is that the render thread clashes with the main thread.

When font size up or down, the main thread will call DxEngine::UpdateFont, in which the render related thing(_dwriteFontFace, for example) is effectively updated. In the meantime, the render thread is happily refreshing the content using PaintBufferLine, which also uses _dwriteFontFace and friends to construct CustomTextLayout. That gives us a race condition. For some reason _dwriteFontFace became a nullptr during the process, causing the crash.

A naive (but acutally working) fix would be adding guard-return for those DX properties to prevent any null-value access. However this is far from ideal. If we going to face these kind of race issue fearlessly, maybe explicit locking is the way to go.

@skyline75489 commented on GitHub (Apr 27, 2020): It's very easy to reproduce this crash with Release build. The root cause I think is that the render thread clashes with the main thread. When font size up or down, the main thread will call `DxEngine::UpdateFont`, in which the render related thing(`_dwriteFontFace`, for example) is effectively updated. In the meantime, the render thread is happily refreshing the content using `PaintBufferLine`, which also uses `_dwriteFontFace` and friends to construct `CustomTextLayout`. That gives us a race condition. For some reason `_dwriteFontFace` became a nullptr during the process, causing the crash. A naive (but acutally working) fix would be adding guard-return for those DX properties to prevent any null-value access. However this is far from ideal. If we going to face these kind of race issue fearlessly, maybe explicit locking is the way to go.
Author
Owner

@zadjii-msft commented on GitHub (Apr 27, 2020):

Oh that's so on me for not locking that call. I'm pretty sure the right solution here is to have the caller get the write lock before calling TriggerFontChange. Thanks for helping debug this!

@zadjii-msft commented on GitHub (Apr 27, 2020): Oh that's so on me for not locking that call. I'm pretty sure the right solution here is to have the caller get the write lock before calling `TriggerFontChange`. Thanks for helping debug this!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7568