From: Vadim Zeitlin Date: Wed, 24 Nov 2010 00:42:45 +0000 (+0000) Subject: Rewind the input stream after failing to load image from it. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/94803e4ec8d61d24ebf9b1e483776d17e55a7ec5?ds=inline Rewind the input stream after failing to load image from it. 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 --- diff --git a/src/common/image.cpp b/src/common/image.cpp index f17d1cbf25..89f35d5d57 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -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 )