-
-
Notifications
You must be signed in to change notification settings - Fork 106
Description
Describe the bug
If you hold down the Next image shortcut, then switch to another folder using the built in navigation, then hold down the next image shortcut again the application will crash.
To Reproduce
Steps to reproduce the behavior:
- Hold down next image shortcut
- Navigate to next folder
- Hold down next image shortcut again
- See error
Expected behavior
The actions should work with no crash.
Additional context
I've tracked down the cause of the crash. The issue is caused by the Timer used for navigation slowdown being disposed of without being set to null:
ImageIterator.cs
private void Dispose(bool disposing, bool cleared = false)
{
if (_disposed)
{
return;
}
if (disposing)
{
_watcher?.Dispose();
if (!cleared)
{
PreLoader.Clear();
}
_timer?.Dispose();
PreLoader.Dispose();
}
_disposed = true;
GC.SuppressFinalize(this);
}Which causes an ObjectDisposedException when the Timer is then used here:
private async ValueTask TimerIteration(int index, CancellationTokenSource? cts)
{
if (_timer is null )
{
_timer = new Timer
{
AutoReset = false,
Enabled = true
};
}
else if (_timer.Enabled)
{
if (!MainKeyboardShortcuts.IsKeyHeldDown)
{
_timer = null;
}
return;
}
_timer.Interval = TimeSpan.FromSeconds(Settings.UIProperties.NavSpeed).TotalMilliseconds;
_timer.Start();
await IterateToIndex(index, cts).ConfigureAwait(false);
}Since the timer is neither null nor initiated. The issue can be fixed by simply setting the timer to null after it is disposed in the Dispose method. But I have not looked enough at the code to see if this is the ideal fix. I only discovered this project today, so I felt it was better to just leave a bug report and let you determine the cleanest fix rather than opening a PR directly.