Skip to content

Commit

Permalink
Merge pull request #177 from satoshinm/filefail
Browse files Browse the repository at this point in the history
Show error and exit on shader/texture file open failure
  • Loading branch information
fogleman committed Apr 6, 2017
2 parents 0676cab + 2dce26f commit ec9fc97
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/util.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

1 comment on commit ec9fc97

@timscriptov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android Support?

Please sign in to comment.