GBA: Properly handle failed loading of PNG savestates

This commit is contained in:
Jeffrey Pfau 2015-07-01 19:56:10 -07:00
parent b3ea09e150
commit 5afa24c656
1 changed files with 12 additions and 7 deletions

View File

@ -229,7 +229,10 @@ static int _loadPNGChunkHandler(png_structp png, png_unknown_chunkp chunk) {
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 @@ static bool _loadPNGState(struct GBA* gba, struct VFile* vf) {
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);
if (success) {
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels);
GBASyncForceFrame(gba->sync);
}
free(pixels);
return true;
return success;
}
#endif