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

Fix accuracy bugs around float/double/int conversions #15098

Merged
merged 2 commits into from
Apr 4, 2023

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Apr 3, 2023

I noticed this bug while resizing my window on my 150% scale display.
Every 3 "snaps" of the window size, it would fail to resize the text
buffer. I found that this occurs, because we convert the swap chain
size from a float into a double, which converts my 597.333313 height
into 597.33331298828125, which then multiplied by 1.5 results in
895.999969482421875. If you just cast this to an integer, it'll
result in a height of 895px instead of the expected 896px.

This PR addresses the issue in two ways:

  • Replace casts to integers with lrint or floor, etc.
  • Remove many of the redundant double <> float conversions.

PR Checklist

  • Resizing my window always resizes the text buffer ✅

@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. Priority-1 A description (P1) labels Apr 3, 2023
@lhecker lhecker force-pushed the dev/lhecker/float-double-inaccuracy-bugs branch from 380e36f to dc9e1db Compare April 3, 2023 23:39
@lhecker lhecker force-pushed the dev/lhecker/float-double-inaccuracy-bugs branch from dc9e1db to c8865d4 Compare April 3, 2023 23:41
@@ -853,8 +852,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// concerned with initialization process. Value forwarded to event handler.
void ControlCore::_updateFont(const bool initialUpdate)
{
const auto newDpi = static_cast<int>(static_cast<double>(USER_DEFAULT_SCREEN_DPI) *
_compositionScale);
const auto newDpi = static_cast<int>(lrint(_compositionScale * USER_DEFAULT_SCREEN_DPI));
Copy link
Member

Choose a reason for hiding this comment

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

this cast seems extraneous or at the very best silly given the auto

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise AuditMode complains that long isn't automatically convertible to int (the parameter type for SetDPI).

@DHowett DHowett merged commit 2a839d8 into main Apr 4, 2023
@DHowett DHowett deleted the dev/lhecker/float-double-inaccuracy-bugs branch April 4, 2023 16:33
@DHowett
Copy link
Member

DHowett commented Apr 4, 2023

@lhecker is this safe for 1.17 as well?

@lhecker
Copy link
Member Author

lhecker commented Apr 4, 2023

Yeah I think this is safe. I've just checked it again and the only functional change is in AppHost.cpp, where instead of using ceil I'm now using lrint (round), because I was pretty sure that the pixel size of the window should be rounded to nearest instead of up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants