PanAndZoom icon indicating copy to clipboard operation
PanAndZoom copied to clipboard

StackOverflow when zooming

Open adirh3 opened this issue 2 years ago • 5 comments

Can't reproduce it, but when tried to zoom while scrolling it happen, hopefully the stack trace might help - image

adirh3 avatar Oct 27 '21 17:10 adirh3

@adirh3 Did you get that exception again, I could not repro the issue.

wieslawsoltes avatar Nov 25 '21 07:11 wieslawsoltes

@adirh3 Did you get that exception again, I could not repro the issue.

Yes, I did, I believe it happens when trying to scroll using the scroll bars with Pan disabled. It happens very rarely, will try to make a repro.

adirh3 avatar Nov 25 '21 08:11 adirh3

I am encountering this issue as well... I have a big image loaded within the zoom area (8255x5504) which makes the GUI kind of slow. From what I can tell, it appears like when the GUI freezes a bit while zooming in and I try to pan using the ScrollViewer bars, I get the StackOverflow at

public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

which makes it tricky to debug.

I happened twice but I am having a hard time trying to get it again. I remember inspecting the exception and the StackTrace was null.

HoneyTauOverTwo avatar Jul 21 '22 16:07 HoneyTauOverTwo

I have the same error, I just used the scroll hard and I moved the scrollbar, it froze and I got that exception, I reproduced the error several times on Desktop

Do you know why this happens?

image

victcdva avatar Jul 28 '22 00:07 victcdva

@adirh3 Did you get that exception again, I could not repro the issue.

@wieslawsoltes Take a look at this. I reproduced the problem. If you pan outside ScrollView and then scroll back using bars the exception is thrown.

ScrollError

I guess I know where the problem is. In the file "ZoomBorder.ILogicalScrollable.cs" at lines 90-91 in function CalculateScrollable variables "offsetX" and "offsetY" are set, The original code is:

var offsetX = ox < 0 ? Abs(ox) : 0;
var offsetY = oy < 0 ? Abs(oy) : 0;

I tried to change this code and after that all worked fine.

var offsetX = ox < 0 ? Abs(ox) - 0.001 : 0.001;
var offsetY = oy < 0 ? Abs(oy) - 0.001 : 0.001;

I know that it is not the right solution, but i hope this will help you fix the problem.

izaksuilov avatar Oct 13 '22 11:10 izaksuilov

I guess I will just add this under line 91 instead:

if (offsetX == 0 && offsetY == 0)
{
    offsetX = 0.001;
}

It should do the trick, right?

HoneyTauOverTwo avatar Oct 17 '22 00:10 HoneyTauOverTwo

I guess I will just add this under line 91 instead:

if (offsetX == 0 && offsetY == 0)
{
    offsetX = 0.001;
}

It should do the trick, right?

No, it won't do the trick, because, as far as I'm concerned, the error occurs when offsetX == minValue || offsetX == maxValue || offsetY == minValue || offsetY == maxValue. So, the minValue is zero, because there is the Abs func. But I'm not sure how to consider the maxValue, so in my example I always subtract 0.001.

So in order not to have any exceptions, I suggest this code:

double delta = 0.001;
var offsetX = ox < 0 ? Abs(ox) - delta : delta;
var offsetY = oy < 0 ? Abs(oy) - delta : delta;

izaksuilov avatar Oct 17 '22 09:10 izaksuilov

is the fix implemented in master branch?

ivanjx avatar May 30 '23 04:05 ivanjx