diff options
| author | Ray <[email protected]> | 2017-06-12 14:21:50 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-06-12 14:21:50 +0200 |
| commit | 8c1f32f2fe25790b3ddd68e8743d488e5b353f8c (patch) | |
| tree | e2a46300ae6a5d47ac53ad21e80b7be3628d5bf6 /src/textures.c | |
| parent | eee8393eb0fd697a3e86d822a4e187c6b487723b (diff) | |
| download | raylib-8c1f32f2fe25790b3ddd68e8743d488e5b353f8c.tar.gz raylib-8c1f32f2fe25790b3ddd68e8743d488e5b353f8c.zip | |
Additional check on file open
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/textures.c b/src/textures.c index 81d36ef8..d249d2be 100644 --- a/src/textures.c +++ b/src/textures.c @@ -191,20 +191,23 @@ Image LoadImage(const char *fileName) int imgBpp = 0; FILE *imFile = fopen(fileName, "rb"); - - // NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...) - image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0); - fclose(imFile); + if (imFile != NULL) + { + // NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...) + image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0); + + fclose(imFile); - image.width = imgWidth; - image.height = imgHeight; - image.mipmaps = 1; + image.width = imgWidth; + image.height = imgHeight; + image.mipmaps = 1; - if (imgBpp == 1) image.format = UNCOMPRESSED_GRAYSCALE; - else if (imgBpp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA; - else if (imgBpp == 3) image.format = UNCOMPRESSED_R8G8B8; - else if (imgBpp == 4) image.format = UNCOMPRESSED_R8G8B8A8; + if (imgBpp == 1) image.format = UNCOMPRESSED_GRAYSCALE; + else if (imgBpp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA; + else if (imgBpp == 3) image.format = UNCOMPRESSED_R8G8B8; + else if (imgBpp == 4) image.format = UNCOMPRESSED_R8G8B8A8; + } } #if defined(SUPPORT_FILEFORMAT_HDR) else if (IsFileExtension(fileName, ".hdr")) |
