Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b5782a

Browse files
committed
Add check to readFile function
1 parent 118c192 commit 7b5782a

20 files changed

Lines changed: 80 additions & 0 deletions

03_Drawing_a_triangle/02_Graphics_pipeline_basics/01_Shader_modules.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ write a simple helper function to load the binary data from the files.
291291

292292
static std::vector<char> readFile(const std::string& filename) {
293293
std::ifstream file(filename, std::ios::ate | std::ios::binary);
294+
295+
if (!file.is_open()) {
296+
throw std::runtime_error("failed to open file!");
297+
}
294298
}
295299
```
296300

code/command_buffers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,10 @@ class HelloTriangleApplication {
771771
static std::vector<char> readFile(const std::string& filename) {
772772
std::ifstream file(filename, std::ios::ate | std::ios::binary);
773773

774+
if (!file.is_open()) {
775+
throw std::runtime_error("failed to open file!");
776+
}
777+
774778
size_t fileSize = (size_t) file.tellg();
775779
std::vector<char> buffer(fileSize);
776780

code/depth_buffering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,10 @@ class HelloTriangleApplication {
14541454
static std::vector<char> readFile(const std::string& filename) {
14551455
std::ifstream file(filename, std::ios::ate | std::ios::binary);
14561456

1457+
if (!file.is_open()) {
1458+
throw std::runtime_error("failed to open file!");
1459+
}
1460+
14571461
size_t fileSize = (size_t) file.tellg();
14581462
std::vector<char> buffer(fileSize);
14591463

code/descriptor_layout.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ class HelloTriangleApplication {
11101110
static std::vector<char> readFile(const std::string& filename) {
11111111
std::ifstream file(filename, std::ios::ate | std::ios::binary);
11121112

1113+
if (!file.is_open()) {
1114+
throw std::runtime_error("failed to open file!");
1115+
}
1116+
11131117
size_t fileSize = (size_t) file.tellg();
11141118
std::vector<char> buffer(fileSize);
11151119

code/descriptor_set.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,10 @@ class HelloTriangleApplication {
11621162
static std::vector<char> readFile(const std::string& filename) {
11631163
std::ifstream file(filename, std::ios::ate | std::ios::binary);
11641164

1165+
if (!file.is_open()) {
1166+
throw std::runtime_error("failed to open file!");
1167+
}
1168+
11651169
size_t fileSize = (size_t) file.tellg();
11661170
std::vector<char> buffer(fileSize);
11671171

code/fixed_functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ class HelloTriangleApplication {
632632
static std::vector<char> readFile(const std::string& filename) {
633633
std::ifstream file(filename, std::ios::ate | std::ios::binary);
634634

635+
if (!file.is_open()) {
636+
throw std::runtime_error("failed to open file!");
637+
}
638+
635639
size_t fileSize = (size_t) file.tellg();
636640
std::vector<char> buffer(fileSize);
637641

code/framebuffers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,10 @@ class HelloTriangleApplication {
709709
static std::vector<char> readFile(const std::string& filename) {
710710
std::ifstream file(filename, std::ios::ate | std::ios::binary);
711711

712+
if (!file.is_open()) {
713+
throw std::runtime_error("failed to open file!");
714+
}
715+
712716
size_t fileSize = (size_t) file.tellg();
713717
std::vector<char> buffer(fileSize);
714718

code/graphics_pipeline_complete.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ class HelloTriangleApplication {
685685
static std::vector<char> readFile(const std::string& filename) {
686686
std::ifstream file(filename, std::ios::ate | std::ios::binary);
687687

688+
if (!file.is_open()) {
689+
throw std::runtime_error("failed to open file!");
690+
}
691+
688692
size_t fileSize = (size_t) file.tellg();
689693
std::vector<char> buffer(fileSize);
690694

code/hello_triangle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,10 @@ class HelloTriangleApplication {
838838
static std::vector<char> readFile(const std::string& filename) {
839839
std::ifstream file(filename, std::ios::ate | std::ios::binary);
840840

841+
if (!file.is_open()) {
842+
throw std::runtime_error("failed to open file!");
843+
}
844+
841845
size_t fileSize = (size_t) file.tellg();
842846
std::vector<char> buffer(fileSize);
843847

code/index_buffer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,10 @@ class HelloTriangleApplication {
10451045
static std::vector<char> readFile(const std::string& filename) {
10461046
std::ifstream file(filename, std::ios::ate | std::ios::binary);
10471047

1048+
if (!file.is_open()) {
1049+
throw std::runtime_error("failed to open file!");
1050+
}
1051+
10481052
size_t fileSize = (size_t) file.tellg();
10491053
std::vector<char> buffer(fileSize);
10501054

0 commit comments

Comments
 (0)