GBA: Properly handle failed loading of PNG savestates
Jeffrey Pfau jeffrey@endrift.com
Wed, 01 Jul 2015 19:56:10 -0700
1 files changed,
12 insertions(+),
7 deletions(-)
jump to
M
src/gba/serialize.c
→
src/gba/serialize.c
@@ -229,7 +229,10 @@ }
struct GBASerializedState state; uLongf len = sizeof(state); uncompress((Bytef*) &state, &len, chunk->data, chunk->size); - return GBADeserialize(png_get_user_chunk_ptr(png), &state); + if (!GBADeserialize(png_get_user_chunk_ptr(png), &state)) { + longjmp(png_jmpbuf(png), 1); + } + return 1; } static bool _loadPNGState(struct GBA* gba, struct VFile* vf) {@@ -243,15 +246,17 @@ }
uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs"); - PNGReadHeader(png, info); - PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS); - PNGReadFooter(png, end); + bool success = PNGReadHeader(png, info); + success = success && PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS); + success = success && PNGReadFooter(png, end); PNGReadClose(png, info, end); - gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels); - GBASyncForceFrame(gba->sync); + if (success) { + gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels); + GBASyncForceFrame(gba->sync); + } free(pixels); - return true; + return success; } #endif