Fixed crash when loading empty shaders

This commit is contained in:
Laurent Gomila 2012-05-09 18:03:54 +02:00
parent 8327870c9f
commit 3c317cab9b

View File

@ -53,9 +53,12 @@ namespace
{ {
file.seekg(0, std::ios_base::end); file.seekg(0, std::ios_base::end);
std::streamsize size = file.tellg(); std::streamsize size = file.tellg();
file.seekg(0, std::ios_base::beg); if (size > 0)
buffer.resize(size); {
file.read(&buffer[0], size); file.seekg(0, std::ios_base::beg);
buffer.resize(size);
file.read(&buffer[0], size);
}
buffer.push_back('\0'); buffer.push_back('\0');
return true; return true;
} }
@ -68,11 +71,16 @@ namespace
// Read the contents of a stream into an array of char // Read the contents of a stream into an array of char
bool getStreamContents(sf::InputStream& stream, std::vector<char>& buffer) bool getStreamContents(sf::InputStream& stream, std::vector<char>& buffer)
{ {
bool success = true;
sf::Int64 size = stream.getSize(); sf::Int64 size = stream.getSize();
buffer.resize(static_cast<std::size_t>(size)); if (size > 0)
sf::Int64 read = stream.read(&buffer[0], size); {
buffer.resize(static_cast<std::size_t>(size));
sf::Int64 read = stream.read(&buffer[0], size);
success = (read == size);
}
buffer.push_back('\0'); buffer.push_back('\0');
return read == size; return success;
} }
} }