mirror of https://github.com/mgba-emu/mgba.git
GBA: Properly handle failed loading of PNG savestates
This commit is contained in:
parent
b3ea09e150
commit
5afa24c656
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue