diff options
| author | raysan5 <raysan5@gmail.com> | 2016-12-25 20:41:36 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-12-25 20:41:36 +0100 |
| commit | 14cdd7fbfff43dbdb869a74dbe846ac38afef532 (patch) | |
| tree | b11b4d05da0463a09f59771da3e865e410b70e7f /src | |
| parent | 852f3d4fd0eec8fcebcf39dfc19b2ccc5b008ba3 (diff) | |
| download | raylib-14cdd7fbfff43dbdb869a74dbe846ac38afef532.tar.gz raylib-14cdd7fbfff43dbdb869a74dbe846ac38afef532.zip | |
Added raw image file reading data check
Diffstat (limited to 'src')
| -rw-r--r-- | src/textures.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/textures.c b/src/textures.c index 7fd4a3d5..8b223ed0 100644 --- a/src/textures.c +++ b/src/textures.c @@ -225,14 +225,22 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int default: TraceLog(WARNING, "Image format not suported"); break; } - fread(image.data, size, 1, rawFile); + int bytes = fread(image.data, size, 1, rawFile); - // TODO: Check if data has been read - - image.width = width; - image.height = height; - image.mipmaps = 0; - image.format = format; + // Check if data has been read successfully + if (bytes < size) + { + TraceLog(WARNING, "[%s] RAW image data can not be read, wrong requested format or size", fileName); + + if (image.data != NULL) free(image.data); + } + else + { + image.width = width; + image.height = height; + image.mipmaps = 0; + image.format = format; + } fclose(rawFile); } @@ -983,7 +991,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec) Color srcCol, dstCol; // Blit pixels, copy source image into destination - // TODO: Probably out-of-bounds blitting could be considering here instead of so much cropping... + // TODO: Probably out-of-bounds blitting could be considered here instead of so much cropping... for (int j = dstRec.y; j < (dstRec.y + dstRec.height); j++) { for (int i = dstRec.x; i < (dstRec.x + dstRec.width); i++) |
