Skip to content

Holding down Next image after switching folder causes instant Crash #260

@EliEron

Description

@EliEron

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:

  1. Hold down next image shortcut
  2. Navigate to next folder
  3. Hold down next image shortcut again
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions