Skip to content

Commit ec9fc97

Browse files
authored
Merge pull request #177 from satoshinm/filefail
Show error and exit on shader/texture file open failure
2 parents 0676cab + 2dce26f commit ec9fc97

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <math.h>
22
#include <stdio.h>
33
#include <stdlib.h>
4+
#include <errno.h>
45
#include "lodepng.h"
56
#include "matrix.h"
67
#include "util.h"
@@ -28,6 +29,10 @@ void update_fps(FPS *fps) {
2829

2930
char *load_file(const char *path) {
3031
FILE *file = fopen(path, "rb");
32+
if (!file) {
33+
fprintf(stderr, "fopen %s failed: %d %s\n", path, errno, strerror(errno));
34+
exit(1);
35+
}
3136
fseek(file, 0, SEEK_END);
3237
int length = ftell(file);
3338
rewind(file);
@@ -134,7 +139,8 @@ void load_png_texture(const char *file_name) {
134139
unsigned int width, height;
135140
error = lodepng_decode32_file(&data, &width, &height, file_name);
136141
if (error) {
137-
fprintf(stderr, "error %u: %s\n", error, lodepng_error_text(error));
142+
fprintf(stderr, "load_png_texture %s failed, error %u: %s\n", file_name, error, lodepng_error_text(error));
143+
exit(1);
138144
}
139145
flip_image_vertical(data, width, height);
140146
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,

0 commit comments

Comments
 (0)