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
const unsigned maxWidth = GetOptionInt(wxIMAGE_OPTION_MAX_WIDTH),
maxHeight = GetOptionInt(wxIMAGE_OPTION_MAX_HEIGHT);
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 ( !handler.LoadFile(this, stream, true/*verbose*/, index) )
+ {
+ if ( posOld != wxInvalidOffset )
+ stream.SeekI(posOld);
+
// rescale the image to the specified size if needed
if ( maxWidth || maxHeight )
// rescale the image to the specified size if needed
if ( maxWidth || maxHeight )