Skip to content

Commit 2b137a1

Browse files
committed
update file read logic
1 parent fdab905 commit 2b137a1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

library/src/Core/Shader.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <fstream>
66
#include <iostream>
7-
#include <iterator>
87
#include <utility>
98

109
namespace
@@ -45,13 +44,18 @@ namespace
4544

4645
bool loadFileContents(const std::filesystem::path& sourcefilePath, std::string& destination)
4746
{
48-
std::ifstream file { sourcefilePath };
49-
if (file.is_open())
47+
std::ifstream file { sourcefilePath, std::ios_base::binary };
48+
if (file)
5049
{
51-
destination = { std::istreambuf_iterator<char> { file }, std::istreambuf_iterator<char> {} };
50+
const std::uintmax_t size = std::filesystem::file_size(sourcefilePath);
51+
if (size > 0)
52+
{
53+
destination.resize(static_cast<std::size_t>(size));
54+
file.read(destination.data(), static_cast<std::streamsize>(size));
55+
}
56+
return true;
5257
}
53-
54-
return file.is_open();
58+
return false;
5559
}
5660
} // namespace
5761

0 commit comments

Comments
 (0)