Show error and exit on shader/texture file open failure

master
Satoshi N. M 2017-04-05 21:38:34 -07:00
parent 0676cabe18
commit 2dce26f149
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "lodepng.h"
#include "matrix.h"
#include "util.h"
@ -28,6 +29,10 @@ void update_fps(FPS *fps) {
char *load_file(const char *path) {
FILE *file = fopen(path, "rb");
if (!file) {
fprintf(stderr, "fopen %s failed: %d %s\n", path, errno, strerror(errno));
exit(1);
}
fseek(file, 0, SEEK_END);
int length = ftell(file);
rewind(file);
@ -134,7 +139,8 @@ void load_png_texture(const char *file_name) {
unsigned int width, height;
error = lodepng_decode32_file(&data, &width, &height, file_name);
if (error) {
fprintf(stderr, "error %u: %s\n", error, lodepng_error_text(error));
fprintf(stderr, "load_png_texture %s failed, error %u: %s\n", file_name, error, lodepng_error_text(error));
exit(1);
}
flip_image_vertical(data, width, height);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,