Francesco Montorsi
2009-05-28 20:12:02 UTC
[cc'ing to Francesco as I'm not sure he's already subscribed to this list]
I read wx-users through gmane and so I didn't subscribe the new list; gmaneworks fine for now ;)
Anyway please cc me also for future issues that appear on wx-users as for the
next months I'll have few free time and so I typically don't read wx-users...
MF> I just grabbed 2.9.0 from SVN and code that worked under 2.8.9 is now
MF> failing (VS 2008, Vista). I am trying to load a .ico file from a Zip stream.
MF> It seems to just be icon files, as I can load any other image type fine.
This was broken by http://svn.wxwidgets.org/viewvc/wx?view=rev&revision=58080
which was apparently necessary to fix some other bug
exactlyMF> failing (VS 2008, Vista). I am trying to load a .ico file from a Zip stream.
MF> It seems to just be icon files, as I can load any other image type fine.
This was broken by http://svn.wxwidgets.org/viewvc/wx?view=rev&revision=58080
which was apparently necessary to fix some other bug
but breaking this is
still unacceptable, of course. I hope Francesco can look into this because
personally I don't see any other solution than reverting this change right
now.
reverting the change is not the right thing. Everytime wx code calls a functionstill unacceptable, of course. I hope Francesco can look into this because
personally I don't see any other solution than reverting this change right
now.
which possibly returns an error/success code, it should check if the call was ok.
Simply disregarding the error/success return code is not a good thing, specially
if the code following that call assumes that the operation was fine (maybe not
all calls changed by r58080 assumed it, but most did).
Here the problem is that, as documented, wxZipInputStream is not a seekable
stream. wxICOHandler, except for the initial SeekI(0), seems to need seekable
streams only in line 1323 of imagbmp.cpp, i.e. when loading a specific icon from
a multi-icon .ico file.
The initial SeekI(0) is present in almost all wx*Handler classes.
I think it's necessary because loading an image implies that
wxICOHandler::DoCanRead(), which moves the "current position" in the stream, is
called before wxICOHandler::DoLoadFile.
I see two possible solutions:
1) reset the current position in the stream in the wxICOHandler::DoCanRead()
function, instead of doing it in DoLoadFile (so that if you call directly
DoLoadFile, it may work also on non-seekable streams).
2) avoid trying to seek the stream directly in SeekI(), if that's possible.
Something like:
Index: src/common/stream.cpp
===================================================================
--- src/common/stream.cpp (revisione 60787)
+++ src/common/stream.cpp (copia locale)
@@ -923,6 +923,14 @@
if (m_lasterror==wxSTREAM_EOF)
m_lasterror=wxSTREAM_NO_ERROR;
+ // avoid unnecessary seek operations: this is not only an optimization; it also
+ // allows code which makes calls to SeekI() which in most cases are unnecessary
+ // (e.g. image handlers) to (possibly) work also with non-seekable streams...
+ if ((mode == wxFromStart && TellI() == pos) ||
+ (mode == wxFromCurrent && pos == 0) ||
+ (mode == wxFromEnd && GetLength() != wxInvalidOffset && TellI() ==
GetLength()-pos))
+ return TellI();
+
/* RR: A call to SeekI() will automatically invalidate any previous
call to Ungetch(), otherwise it would be possible to SeekI() to
one position, unread some bytes there, SeekI() to another position
Could you test this change and see if your icon gets loaded?
If the code works then it needs to be copied also in wxBufferedInputStream (see
the initial comment in wxInputStream::SeekI).
Francesco
PS: This issue remembers me of http://trac.wxwidgets.org/ticket/10373 which in
the last comment proposes a further possible enhancement to wxInputStream::SeekI().