From 0edf79cb898977af8e2d30f8ca3c06a124a47f9c Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Thu, 9 May 2013 10:24:45 +0200 Subject: [PATCH] loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349) --- src/SFML/Audio/SoundFile.cpp | 3 +++ src/SFML/Graphics/Font.cpp | 3 +++ src/SFML/Graphics/ImageLoader.cpp | 3 +++ src/SFML/Graphics/Shader.cpp | 1 + 4 files changed, 10 insertions(+) diff --git a/src/SFML/Audio/SoundFile.cpp b/src/SFML/Audio/SoundFile.cpp index 70afa8aa6..0b19138a0 100644 --- a/src/SFML/Audio/SoundFile.cpp +++ b/src/SFML/Audio/SoundFile.cpp @@ -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); diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 0e4678c1d..bc9cf368c 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -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)); diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 828ac07ad..340c5c88c 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -181,6 +181,9 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector& 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; diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 0d25db465..32c49ee6c 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -76,6 +76,7 @@ namespace if (size > 0) { buffer.resize(static_cast(size)); + stream.seek(0); sf::Int64 read = stream.read(&buffer[0], size); success = (read == size); }