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

[Blazor] prevent infinite loop in SKCanvasView #1889

Merged
merged 2 commits into from
Dec 14, 2021
Merged

[Blazor] prevent infinite loop in SKCanvasView #1889

merged 2 commits into from
Dec 14, 2021

Conversation

JensKrumsieck
Copy link
Contributor

Description of Change

Prevents infinite resize loop - i don't know if this is the most elegant solution, but it works.

Added the following line to OnSizeChanged Event of Blazor SKCanvasView

if (Math.Round(canvasSize.Width * dpi) == newSize.Width && Math.Round(canvasSize.Height * dpi) == newSize.Height)
    return;

If Monitor scaling is applied in Windows Settings App, the view keeps multiplying the canvas size with the DPI (in my case being 1.25 for 125% scaling) in the Invalidate-Method.
The Canvas will be resized to the new size which results in the SizeWatcherInterop to fire its OnSizeChanged Event which will set canvasSize to newSize and calls Invalidate again to start infinite loop, also mentioned here:
#1838 (comment)

Bugs Fixed
#1838

API Changes
None

Behavioral Changes
None

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Updated documentation

@JensKrumsieck JensKrumsieck changed the title prevent infinite loop [Blazor] prevent infinite loop in SKCanvasView Dec 12, 2021
Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

This makes sense. Just wondering if we should just be casting to int instead of rounding? That is what is happening on line 80.

Not sure if that was causing an issue and you already tried that. Feels like it should work.

@JensKrumsieck
Copy link
Contributor Author

You are right. I looked back at the console output from #1838 (comment)

DPI: 1,25 -> predicting: 1952,5: 1463,75
1952 : 1463

It cuts the digits after the comma instead of rounding.
I appended 5385f9d

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.

2 participants