loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349)

This commit is contained in:
Laurent Gomila 2013-05-09 10:24:45 +02:00
parent 5453d11d18
commit 0edf79cb89
4 changed files with 10 additions and 0 deletions

View File

@ -164,6 +164,9 @@ bool SoundFile::openRead(InputStream& stream)
m_stream.source = &stream;
m_stream.size = stream.getSize();
// Make sure that the stream's reading position is at the beginning
stream.seek(0);
// Open the sound file
SF_INFO fileInfo;
m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_stream);

View File

@ -194,6 +194,9 @@ bool Font::loadFromStream(InputStream& stream)
}
m_library = library;
// Make sure that the stream's reading position is at the beginning
stream.seek(0);
// Prepare a wrapper for our stream, that we'll pass to FreeType callbacks
FT_StreamRec* rec = new FT_StreamRec;
std::memset(rec, 0, sizeof(*rec));

View File

@ -181,6 +181,9 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& p
// Clear the array (just in case)
pixels.clear();
// Make sure that the stream's reading position is at the beginning
stream.seek(0);
// Setup the stb_image callbacks
stbi_io_callbacks callbacks;
callbacks.read = &read;

View File

@ -76,6 +76,7 @@ namespace
if (size > 0)
{
buffer.resize(static_cast<std::size_t>(size));
stream.seek(0);
sf::Int64 read = stream.read(&buffer[0], size);
success = (read == size);
}