Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock for writing in ControlCore::SetBackgroundOpacity #10357

Merged
1 commit merged into from
Jun 9, 2021

Conversation

miniksa
Copy link
Member

@miniksa miniksa commented Jun 7, 2021

PR Checklist

  • Closes random crash that @lhecker sent me on Teams
  • I work here.

Detailed Description of the Pull Request / Additional comments

  • Any change to the renderer engine has to be done under lock. Leonard gave me a crash where the dirty rectangles changed out from under the renderer thread. By inspection, only one spot in ControlCore is modifying the engine outside of lock.... here. The dump is too far along to definitively prove the issue and it's sort of a race so its difficult to repro. But the theory is sound that all writes to the dirty regions must be done under lock. So here's a fix.

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a bit of regexp:

(render)?\S*engine\S*->(SetCallback|SetWarningCallback|ToggleShaderEffects|SetRetroTerminalEffect|SetPixelShaderPath|SetForceFullRepaintRendering|SetSoftwareRendering|GetSwapChainHandle|Invalidate|InvalidateCursor|InvalidateSystem|InvalidateSelection|InvalidateScroll|InvalidateAll|InvalidateCircling|PrepareForTeardown|StartPaint|EndPaint|RequiresContinuousRedraw|WaitUntilCanRender|Present|ScrollFrame|PrepareRenderInfo|PaintBackground|PaintBufferLine|PaintBufferGridLines|PaintSelection|PaintCursor|UpdateDrawingBrushes|UpdateFont|UpdateDpi|UpdateViewport|GetProposedFont|GetDirtyArea|GetFontSize|IsGlyphWideByFont|GetViewportInCharacters|GetViewportInPixels|SetSelectionBackground|SetAntialiasingMode|SetDefaultTextBackgroundOpacity|UpdateHyperlinkHoveredId)

...I found some more places that might need fixing:

But that doesn't make this change in itself any less correct.
👉 Approve.

@miniksa
Copy link
Member Author

miniksa commented Jun 7, 2021

With a bit of regexp:

(render)?\S*engine\S*->(SetCallback|SetWarningCallback|ToggleShaderEffects|SetRetroTerminalEffect|SetPixelShaderPath|SetForceFullRepaintRendering|SetSoftwareRendering|GetSwapChainHandle|Invalidate|InvalidateCursor|InvalidateSystem|InvalidateSelection|InvalidateScroll|InvalidateAll|InvalidateCircling|PrepareForTeardown|StartPaint|EndPaint|RequiresContinuousRedraw|WaitUntilCanRender|Present|ScrollFrame|PrepareRenderInfo|PaintBackground|PaintBufferLine|PaintBufferGridLines|PaintSelection|PaintCursor|UpdateDrawingBrushes|UpdateFont|UpdateDpi|UpdateViewport|GetProposedFont|GetDirtyArea|GetFontSize|IsGlyphWideByFont|GetViewportInCharacters|GetViewportInPixels|SetSelectionBackground|SetAntialiasingMode|SetDefaultTextBackgroundOpacity|UpdateHyperlinkHoveredId)

...I found some more places that might need fixing:

But that doesn't make this change in itself any less correct.
👉 Approve.

The first 3 are probably "LockForReading" if they can't deal with a potentially dirty or invalid piece of data.
The last one is on a separate temporary engine that isn't associated with the main drawing pipeline so it doesn't need a lock.

But yes. Thank you.

@lhecker
Copy link
Member

lhecker commented Jun 7, 2021

GetSwapChainHandle "technically" needs a write lock, in case that the swap chain doesn't exist yet (otherwise - theoretically - multiple threads could race and create more than one swap chain).
If we force the creation of the swap chain early in ControlCore::Initialize we can safely use a shared reading lock.
...we don't need any locks, as the swap chain is constant throughout the renderer's life, isn't it?

@miniksa
Copy link
Member Author

miniksa commented Jun 9, 2021

GetSwapChainHandle "technically" needs a write lock, in case that the swap chain doesn't exist yet (otherwise - theoretically - multiple threads could race and create more than one swap chain).
If we force the creation of the swap chain early in ControlCore::Initialize we can safely use a shared reading lock.
...we don't need any locks, as the swap chain is constant throughout the renderer's life, isn't it?

I think so. It might have adjusted a bit with the multiprocess stuff. I don't want to mess with it while @zadjii-msft technically has those things in flight.

@miniksa miniksa added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 9, 2021
@ghost
Copy link

ghost commented Jun 9, 2021

Hello @miniksa!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 94d39b7 into main Jun 9, 2021
@ghost ghost deleted the dev/miniksa/leonard_crash branch June 9, 2021 16:55
DHowett pushed a commit that referenced this pull request Jul 7, 2021
## PR Checklist
* [x] Closes random crash that @lhecker sent me on Teams
* [x] I work here.

## Detailed Description of the Pull Request / Additional comments
- Any change to the renderer engine has to be done under lock. Leonard gave me a crash where the dirty rectangles changed out from under the renderer thread. By inspection, only one spot in `ControlCore` is modifying the engine outside of lock.... here. The dump is too far along to definitively prove the issue and it's sort of a race so its difficult to repro. But the theory is sound that all writes to the dirty regions must be done under lock. So here's a fix.

(cherry picked from commit 94d39b7)
@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal v1.9.1942.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal Preview v1.10.1933.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants