Skip to content

Commit

Permalink
Fix divide by zero exception occasionally occurring when exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed May 17, 2023
1 parent 9f00b97 commit 5eb724c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PicView/ChangeImage/Preloader.cs
Expand Up @@ -194,18 +194,21 @@ internal static void Remove(int key)
Parallel.For(0, PositiveIterations, i =>
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (nextStartingIndex + i) % Pics.Count;
_ = AddAsync(index).ConfigureAwait(false);
});
Parallel.For(0, NegativeIterations, i =>
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (prevStartingIndex - i + Pics.Count) % Pics.Count;
_ = AddAsync(index).ConfigureAwait(false);
});
if (Pics.Count > MaxCount + NegativeIterations)
{
for (var i = 0; i < NegativeIterations; i++)
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (deleteIndex - i + Pics.Count) % Pics.Count;
Remove(index);
}
Expand All @@ -219,18 +222,21 @@ internal static void Remove(int key)
Parallel.For(0, PositiveIterations, i =>
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (nextStartingIndex - i + Pics.Count) % Pics.Count;
_ = AddAsync(index).ConfigureAwait(false);
});
Parallel.For(0, NegativeIterations, i =>
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (prevStartingIndex + i) % Pics.Count;
_ = AddAsync(index).ConfigureAwait(false);
});
if (Pics.Count > MaxCount + NegativeIterations)
{
for (var i = 0; i < NegativeIterations; i++)
{
if (Pics.Count is 0) return; // Fix divide by zero exception occasionally occurring when exiting
var index = (deleteIndex + i) % Pics.Count;
Remove(index);
}
Expand Down

0 comments on commit 5eb724c

Please sign in to comment.