mirror of
https://github.com/SFML/SFML.git
synced 2024-11-29 06:41:05 +08:00
loadFromStream functions now explicitly reset the stream (seek(0)) before starting to read (#349)
This commit is contained in:
parent
5453d11d18
commit
0edf79cb89
@ -164,6 +164,9 @@ bool SoundFile::openRead(InputStream& stream)
|
|||||||
m_stream.source = &stream;
|
m_stream.source = &stream;
|
||||||
m_stream.size = stream.getSize();
|
m_stream.size = stream.getSize();
|
||||||
|
|
||||||
|
// Make sure that the stream's reading position is at the beginning
|
||||||
|
stream.seek(0);
|
||||||
|
|
||||||
// Open the sound file
|
// Open the sound file
|
||||||
SF_INFO fileInfo;
|
SF_INFO fileInfo;
|
||||||
m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_stream);
|
m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_stream);
|
||||||
|
@ -194,6 +194,9 @@ bool Font::loadFromStream(InputStream& stream)
|
|||||||
}
|
}
|
||||||
m_library = library;
|
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
|
// Prepare a wrapper for our stream, that we'll pass to FreeType callbacks
|
||||||
FT_StreamRec* rec = new FT_StreamRec;
|
FT_StreamRec* rec = new FT_StreamRec;
|
||||||
std::memset(rec, 0, sizeof(*rec));
|
std::memset(rec, 0, sizeof(*rec));
|
||||||
|
@ -181,6 +181,9 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& p
|
|||||||
// Clear the array (just in case)
|
// Clear the array (just in case)
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
|
|
||||||
|
// Make sure that the stream's reading position is at the beginning
|
||||||
|
stream.seek(0);
|
||||||
|
|
||||||
// Setup the stb_image callbacks
|
// Setup the stb_image callbacks
|
||||||
stbi_io_callbacks callbacks;
|
stbi_io_callbacks callbacks;
|
||||||
callbacks.read = &read;
|
callbacks.read = &read;
|
||||||
|
@ -76,6 +76,7 @@ namespace
|
|||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
buffer.resize(static_cast<std::size_t>(size));
|
buffer.resize(static_cast<std::size_t>(size));
|
||||||
|
stream.seek(0);
|
||||||
sf::Int64 read = stream.read(&buffer[0], size);
|
sf::Int64 read = stream.read(&buffer[0], size);
|
||||||
success = (read == size);
|
success = (read == size);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user