diff --git a/libretro-common/file/nbio/nbio_stdio.c b/libretro-common/file/nbio/nbio_stdio.c index 3fd7a19df4..88bf5af78e 100644 --- a/libretro-common/file/nbio/nbio_stdio.c +++ b/libretro-common/file/nbio/nbio_stdio.c @@ -61,6 +61,9 @@ struct nbio_t* nbio_open(const char * filename, enum nbio_mode_t mode) void nbio_begin_read(struct nbio_t* handle) { + if (!handle) + return; + if (handle->op >= 0) { puts("ERROR - attempted file read operation while busy"); @@ -90,6 +93,9 @@ bool nbio_iterate(struct nbio_t* handle) { size_t amount = 65536; + if (!handle) + return false; + if (amount > handle->len - handle->progress) amount = handle->len - handle->progress; @@ -126,6 +132,8 @@ void nbio_resize(struct nbio_t* handle, size_t len) void* nbio_get_ptr(struct nbio_t* handle, size_t* len) { + if (!handle) + return NULL; if (len) *len = handle->len; if (handle->op == -1) diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index 9a13f063f3..325e81ad2d 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -28,6 +28,8 @@ #include #include +#include + #ifdef GEKKO #include #endif @@ -43,6 +45,8 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #endif +//#define NONBLOCKING_TEST + static const uint8_t png_magic[8] = { 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a, }; @@ -805,7 +809,20 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, bool has_iend = false; bool has_plte = false; bool ret = true; - FILE *file = fopen(path, "rb"); + FILE *file; +#ifdef NONBLOCKING_TEST + size_t size = 0; + bool looped = false; + struct nbio_t* read = nbio_open(path, NBIO_READ); + void* ptr = nbio_get_ptr(read, &size); + nbio_begin_read(read); + + while (!nbio_iterate(read)) looped=true; + ptr = nbio_get_ptr(read, &size); + (void)ptr; + (void)looped; +#endif + file = fopen(path, "rb"); if (!file) { @@ -848,6 +865,9 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, width, height); end: +#ifdef NONBLOCKING_TEST + nbio_free(read); +#endif if (file) fclose(file); if (!ret)