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

Fixes crash when specifying invalid font #2153

Merged
merged 4 commits into from
Jul 30, 2019
Merged

Conversation

miniksa
Copy link
Member

@miniksa miniksa commented Jul 30, 2019

Summary of the Pull Request

Adds fallback routine for when a font name is missing instead of crashing due to uncaught exception thrown when font cannot be found.

PR Checklist

Detailed Description of the Pull Request / Additional comments

For GDI and for DirectX using the stock Layouts and Formats, if your chosen font face name isn't found... something else is just picked on your behalf. When I wrote our custom DX code, I instead threw an exception when I couldn't find the chosen font face. That exception was uncaught and led to a crash.

I decided to just make the custom code act more like the stock code and attempt to choose a fallback if we cannot find what you've requested. I also improved a bit of the passing around of the chosen font name and added locale name information while I was at it.

Validation Steps Performed

  • Opened settings
  • Set font name to "arse"
  • Watched as nothing changed from previous Consolas selection
  • Closed application
  • Relaunched
  • Didn't crash this time, it just chose Consolas instead

…le name. Retrieve the font name while retrieving the font object. Use retrieved data in the _GetProposedFont methods instead of re-resolving it.
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

Should we maybe update SettingsSchem.md with a note that says something like "if we can't find the font specified, we'll try falling back to Consolas"

src/renderer/dx/DxRenderer.cpp Outdated Show resolved Hide resolved
src/renderer/dx/DxRenderer.cpp Show resolved Hide resolved
// - style - Normal, italic, etc.
// Return Value:
// - Smart pointer holding interface reference for queryable font data.
[[nodiscard]] Microsoft::WRL::ComPtr<IDWriteFontFace1> DxEngine::_ResolveFontFaceWithFallback(std::wstring& familyName,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be the not-oft-used std::wstring& const?

src/renderer/dx/DxRenderer.cpp Outdated Show resolved Hide resolved
src/renderer/dx/DxRenderer.cpp Outdated Show resolved Hide resolved

// Make our output buffer and resize it so it is allocated.
std::wstring retVal;
retVal.resize(length);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to remove the extra terminating null on the wstring after this?

Copy link
Contributor

Choose a reason for hiding this comment

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

er after it is populated

@DHowett-MSFT
Copy link
Contributor

Should we cherry-pick this back to 20H1?

@miniksa
Copy link
Member Author

miniksa commented Jul 30, 2019

Should we cherry-pick this back to 20H1?

Maybe? It's only for the DX renderer which is hidden unless you know the magic dance so it's not high impact. But it is early so it might be an easy sell?

@miniksa
Copy link
Member Author

miniksa commented Jul 30, 2019

This seems reasonable to me.

Should we maybe update SettingsSchem.md with a note that says something like "if we can't find the font specified, we'll try falling back to Consolas"

Sure.

@miniksa miniksa merged commit 56589c0 into master Jul 30, 2019
@miniksa miniksa deleted the dev/miniksa/font-crash branch July 30, 2019 21:32
@ghost
Copy link

ghost commented Aug 3, 2019

🎉Windows Terminal Preview v0.3.2142.0 has been released which incorporates this pull request.:tada:

Handy links:

DHowett-MSFT pushed a commit that referenced this pull request Aug 6, 2019
* Stop the crash with fonts by trying a few fallback/backup fonts if we can't find what was selected.
* Create fallback pattern for finding a font. Resolve and pass the locale name. Retrieve the font name while retrieving the font object. Use retrieved data in the _GetProposedFont methods instead of re-resolving it.
* Add details to schema about fallback. Finish comment explaining fallback pattern to doc comment on method.

(cherry picked from commit 56589c0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specifying a font to be used in profile that does not exist causes the app the crash
3 participants