DiffusionToolkit icon indicating copy to clipboard operation
DiffusionToolkit copied to clipboard

[BUG] An unhandled exception occured / Index was out of range

Open Kornifikator opened this issue 7 months ago • 22 comments

Describe the bug I start the programme on windows 10 and want to navigate to an image folder with a few subfolders and thousands of images. When double-clicking on the image folder the programme shows an error message (see screenshot) and shuts down completely.

Version: Version 1.9

Tool: SDWebUI Forge and ComfyUI.

To Reproduce See bug description.

Expected behavior I want to enter the folder, see and select images to read the metadata of the images.

Image

Kornifikator avatar Apr 26 '25 10:04 Kornifikator

Am also getting the same error. Everything appears to be working okay, but if I go to folders and try to open a folder to see the images contained within it, I get the Unhandled Exception error and the program closes. I can view images via albums, search, etc without issue.

jonk999 avatar Apr 28 '25 01:04 jonk999

Can you try this build:

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14713952094/artifacts/3023901450

RupertAvery avatar Apr 28 '25 17:04 RupertAvery

I also get this error when I open a folder containing images.

Light-x02 avatar Apr 28 '25 21:04 Light-x02

If this happens when you open an image, can you upload the image here? Or upload the error in the log file?

RupertAvery avatar Apr 29 '25 09:04 RupertAvery

If this happens when you open an image, can you upload the image here? Or upload the error in the log file?

it does not matter. the same error pops when going in the TAB search images (CTRL+2) below folder TAB. so it is not about quality of image. plus please i was unable to find image FILE SIZE in (MB or KB etc) thanks for Adding the SIZE in sorting options. but it does not show file size. like what is the actual size on the system. i can see pixel size in the image parameter side panels. 2000X3000 pixels. for example but is it 14 mb or 30 mb, i can't see such option to view. thanks

danrazor avatar Apr 29 '25 11:04 danrazor

It's not when opening an image that the error occurs, but when clicking on a folder for me.

Image

Image

Light-x02 avatar Apr 29 '25 11:04 Light-x02

If this happens when you open an image, can you upload the image here? Or upload the error in the log file?

Hello, I found the problem in the file "ThumbnailView.xaml.Page.cs"

I have modified "public void ReloadThumbnailsView()"

Here's my fix:

public void ReloadThumbnailsView()
{
    var wrapPanel = GetChildOfType<WrapPanel>(this);

    if (wrapPanel == null || wrapPanel.Children.Count == 0)
        return; // 🔐 Protects against out-of-range indexing here

    var scrollViewer = GetChildOfType<ScrollViewer>(this);
    if (scrollViewer == null)
        return;

    var offset = scrollViewer.VerticalOffset;
    var height = scrollViewer.ViewportHeight;

    var item = wrapPanel.Children[0] as ListViewItem;

    // 🛡️ Additional verification
    if (item == null)
        return;

    var preloadSize = item.ActualHeight * 2;

    double top = 0;
    double left = 0;
    var maxHeight = item.ActualHeight;

    for (var i = 0; i < wrapPanel.Children.Count; i++)
    {
        item = wrapPanel.Children[i] as ListViewItem;

        if (item == null)
            continue; // 🛡️ Additional verification

        if (top + item.ActualHeight >= (offset - preloadSize) && top <= (offset + height + preloadSize))
        {
            if (item?.DataContext is ImageEntry { LoadState: LoadState.Unloaded } imageEntry)
            {
                ServiceLocator.ThumbnailService.QueueImage(imageEntry);
            }
        }

        if (item.ActualHeight > maxHeight)
        {
            maxHeight = item.ActualHeight;
        }

        left += item.ActualWidth;

        if (left + item.ActualWidth > wrapPanel.ActualWidth)
        {
            top += maxHeight;
            maxHeight = item.ActualHeight;
            left = 0;
        }
    }
}

I compiled and executed and the problem disappeared and I see my list of folders and I can click on them :)

Image

Light-x02 avatar Apr 29 '25 12:04 Light-x02

how do we non programing dumb users fix this?

danrazor avatar Apr 29 '25 13:04 danrazor

how do we non programing dumb users fix this?

You have to wait for the creator to apply the modification and make the update :)

Light-x02 avatar Apr 29 '25 13:04 Light-x02

Thanks for fixing this, @Light-x02 !

RupertAvery avatar Apr 29 '25 15:04 RupertAvery

Here's the fixed build

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

RupertAvery avatar Apr 29 '25 15:04 RupertAvery

Here's the fixed build

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Thanks. That fixes it for me. Initial navigation is slow and I thought the program had hung (I have a fairly large number of folders), but after that initial load or whatever is performed it's then quick.

jonk999 avatar Apr 29 '25 20:04 jonk999

Here's the fixed build

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Hi Rupert, your application is EXTREMELY excellent but I too am having the same error. It only happens when I try to open a sub folder within the main folder which I have added to Diffusion Toolkit. Your link doesn't work :( How do I get the updated fixed build?

gohan2091 avatar Apr 30 '25 00:04 gohan2091

Here's the fixed build https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Hi Rupert, your application is EXTREMELY excellent but I too am having the same error. It only happens when I try to open a sub folder within the main folder which I have added to Diffusion Toolkit. Your link doesn't work :( How do I get the updated fixed build?

Did you put this build on? It's the FIX.

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Light-x02 avatar Apr 30 '25 00:04 Light-x02

Here's the fixed build https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Hi Rupert, your application is EXTREMELY excellent but I too am having the same error. It only happens when I try to open a sub folder within the main folder which I have added to Diffusion Toolkit. Your link doesn't work :( How do I get the updated fixed build?

Did you put this build on? It's the FIX.

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Odd, the link gave me a 404 error when I posted "Page not found" but now it works. Oh well lol, thanks, I'll give it a try. Hope to see this available via the update within the application for everyone.

gohan2091 avatar Apr 30 '25 00:04 gohan2091

Here's the fixed build

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

Thanks guys! This fixed it for me! Great software and great fix! Big respect!

Kornifikator avatar Apr 30 '25 08:04 Kornifikator

Getting this error and the link above is 404

5n0wCr45h avatar May 18 '25 05:05 5n0wCr45h

...and now the link works...weird...

5n0wCr45h avatar May 19 '25 16:05 5n0wCr45h

1.9.1 fixed the issue for me. Consider publishing to releases/?

The only gotcha in 1.9.1 is that I can't figure out how to add more new folders from the Root Folders view, which I could in V1.9.0 via the settings / general. So I used 1.9.0 to add more folders, then switched back to 1.9.1 to actually view them 😉.

fdwr avatar Jun 30 '25 23:06 fdwr

just downloaded a fresh copy deleted the original and the roaming files and still have this issue

tampadesignr avatar Jul 25 '25 11:07 tampadesignr

this is still an issue for me in the latest release (1.9.0) Has the above fix been pushed to the latest builds?

The artifact link that was linked previously:

https://github.com/RupertAvery/DiffusionToolkit/actions/runs/14734845909/artifacts/3030902988

is no longer functional.

jwoeifjofwefawsfasd avatar Aug 08 '25 19:08 jwoeifjofwefawsfasd

Hey @jwoeifjofwefawsfasd @fdwr and anyone else running into issues with 1.9.0:

You can download the master zip / code through this link: https://github.com/RupertAvery/DiffusionToolkit/archive/refs/heads/master.zip

You can also click the green <> Code button in the middle - middle right on the Code page for Diffusion Toolkit, and select Download ZIP. Once you unzip or extract all of the files into a folder, run the "publish.cmd" file. It should properly work after that. You MAY have to have .NET 6 SDK installed, however, I had ran publish.cmd previously and it didn't need .NET 6 SDK.

After you run the publish.cmd file, all of Diffusion Toolkit gets placed into a new folder titled "build". You can rename it or move it to wherever you like, but that has all of the normal files that you'd see if you downloaded any of the releases. Running Diffusion Toolkit.exe should then not give you any errors (at least, not of this Index variety).

Let me know if you have any further issues.

TheGho7t avatar Aug 17 '25 21:08 TheGho7t