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
This commit is contained in:
Vadim Zeitlin 2010-11-24 00:42:45 +00:00
parent 3f74b7aeb6
commit 94803e4ec8

View 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 )