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;
|
struct GBASerializedState state;
|
||||||
uLongf len = sizeof(state);
|
uLongf len = sizeof(state);
|
||||||
uncompress((Bytef*) &state, &len, chunk->data, chunk->size);
|
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) {
|
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);
|
uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
|
||||||
|
|
||||||
PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs");
|
PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs");
|
||||||
PNGReadHeader(png, info);
|
bool success = PNGReadHeader(png, info);
|
||||||
PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS);
|
success = success && PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS);
|
||||||
PNGReadFooter(png, end);
|
success = success && PNGReadFooter(png, end);
|
||||||
PNGReadClose(png, info, end);
|
PNGReadClose(png, info, end);
|
||||||
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels);
|
if (success) {
|
||||||
GBASyncForceFrame(gba->sync);
|
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels);
|
||||||
|
GBASyncForceFrame(gba->sync);
|
||||||
|
}
|
||||||
|
|
||||||
free(pixels);
|
free(pixels);
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue