]> git.saurik.com Git - wxWidgets.git/commitdiff
Rewind the input stream after failing to load image from it.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Nov 2010 00:42:45 +0000 (00:42 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Nov 2010 00:42:45 +0000 (00:42 +0000)
For seekable streams, don't change the current position when loading image
fails. This allows the subsequent image handlers to succeed during image
format auto-detection even if a previous, erroneously chosen, handler failed.

Closes #12702.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66252 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/image.cpp

index f17d1cbf2511f2d136cfd4bdaa6baf05fb864052..89f35d5d5743ba4a0360fb514f6ea69f1a134aed 100644 (file)
@@ -2376,8 +2376,20 @@ bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
     const unsigned maxWidth = GetOptionInt(wxIMAGE_OPTION_MAX_WIDTH),
                    maxHeight = GetOptionInt(wxIMAGE_OPTION_MAX_HEIGHT);
 
+    // Preserve the original stream position if possible to rewind back to it
+    // if we failed to load the file -- maybe the next handler that we try can
+    // succeed after us then.
+    wxFileOffset posOld = wxInvalidOffset;
+    if ( stream.IsSeekable() )
+        posOld = stream.TellI();
+
     if ( !handler.LoadFile(this, stream, true/*verbose*/, index) )
+    {
+        if ( posOld != wxInvalidOffset )
+            stream.SeekI(posOld);
+
         return false;
+    }
 
     // rescale the image to the specified size if needed
     if ( maxWidth || maxHeight )