cyotek / imagelistview

Automatically exported from code.google.com/p/imagelistview
4 stars 0 forks source link

NullReferenceExceptions #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am getting a null reference exception after doing some manipulations (like 
flipping the image horizontally with my own code).

First, everything is OK and displayed successfully. After I do the operation on 
a rather large file (1024x768 JPEG), the error occurs (sorry, german only):

-------
Exception occurred: Der Objektverweis wurde nicht auf eine Objektinstanz 
festgelegt.,    bei Manina.Windows.Forms.ImageListViewItemCacheManager.DoWork() 
in 
C:\Ablage\ilv-svn\imagelistview-read-only\ImageListViewItemCacheManager.cs:Zeile
 232.
   bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()
-------

So it seems that in line 232 of the file "ImageListViewItemCacheManager.cs" a 
null reference exception occures.

My code basically does:

--------
using (var img = Image.FromFile(item.FileName))
{
    img.RotateFlip(RotateFlipType.RotateNoneFlipX);
    img.Save(item.FileName);
}
--------

My assumption is that the background processing struggles when accessing the 
file that I have still in use or something like that.

Original issue reported on code.google.com by uwe.k...@gmail.com on 6 Sep 2010 at 5:25

GoogleCodeExporter commented 9 years ago
Can you try the BeginEdit and EndEdit methods of ImageListViewItem? They should 
prevent collisions with the cache thread.

Thanks,
Ozgur

Original comment by oozcitak on 6 Sep 2010 at 5:27

GoogleCodeExporter commented 9 years ago
Sorry, I pasted too few code, I already do this, this is the whole function:

        public void PerformFlipHorizontally()
        {
            foreach (var item in thumbnailListView.SelectedItems)
            {
                // My code:
                var asset = (WebImageAsset)item.Tag;
                asset.CommitState = CommitState.Modified;

                // The image list view code:
                item.BeginEdit();
                using (var img = Image.FromFile(item.FileName))
                {
                    img.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    img.Save(item.FileName);
                }
                item.Update();
                item.EndEdit();
            }

            // Again, my code:
            notifyNeedUpdatePreview();
            PerformUpdateUI();
        }

Original comment by uwe.k...@gmail.com on 6 Sep 2010 at 6:17

GoogleCodeExporter commented 9 years ago
It even gets worse with the fact, that the application completely crashes (I 
guess, because that the thread has no exception handler and it is not always 
promoted to the UnhandledException) handler.

Original comment by uwe.k...@gmail.com on 6 Sep 2010 at 7:07

GoogleCodeExporter commented 9 years ago
Something about your code above (not related to the issue). You do not need to 
call item.Update since item.EndEdit will call it for you. Just a FYI.

Original comment by oozcitak on 7 Sep 2010 at 10:47

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r369.

Original comment by oozcitak on 7 Sep 2010 at 10:58