From 3c317cab9bccf11d34904637d48c912542234165 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Wed, 9 May 2012 18:03:54 +0200 Subject: [PATCH] Fixed crash when loading empty shaders --- src/SFML/Graphics/Shader.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 7fe7f835..d219aa66 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -53,9 +53,12 @@ namespace { file.seekg(0, std::ios_base::end); std::streamsize size = file.tellg(); - file.seekg(0, std::ios_base::beg); - buffer.resize(size); - file.read(&buffer[0], size); + if (size > 0) + { + file.seekg(0, std::ios_base::beg); + buffer.resize(size); + file.read(&buffer[0], size); + } buffer.push_back('\0'); return true; } @@ -68,11 +71,16 @@ namespace // Read the contents of a stream into an array of char bool getStreamContents(sf::InputStream& stream, std::vector& buffer) { + bool success = true; sf::Int64 size = stream.getSize(); - buffer.resize(static_cast(size)); - sf::Int64 read = stream.read(&buffer[0], size); + if (size > 0) + { + buffer.resize(static_cast(size)); + sf::Int64 read = stream.read(&buffer[0], size); + success = (read == size); + } buffer.push_back('\0'); - return read == size; + return success; } }