GBA: Better memory handling with PNG savestates

This commit is contained in:
Jeffrey Pfau 2015-08-30 19:14:59 -07:00
parent 34fd6769e6
commit a8192f47e2
2 changed files with 11 additions and 4 deletions

View File

@ -14,6 +14,7 @@ Misc:
- ARM7: Combine shifter-immediate and shifter-register functions to reduce binary size
- SDL: Support fullscreen in SDL 1.2
- GBA: Attempting to save a screenshot-style savestate should be allowed without libpng
- GBA: Better memory handling with PNG savestates
0.3.0: (2015-08-16)
Features:

View File

@ -234,12 +234,14 @@ static int _loadPNGChunkHandler(png_structp png, png_unknown_chunkp chunk) {
if (strcmp((const char*) chunk->name, "gbAs") != 0) {
return 0;
}
struct GBASerializedState state;
uLongf len = sizeof(state);
uncompress((Bytef*) &state, &len, chunk->data, chunk->size);
if (!GBADeserialize(png_get_user_chunk_ptr(png), &state)) {
struct GBASerializedState* state = malloc(sizeof(*state));
uLongf len = sizeof(*state);
uncompress((Bytef*) state, &len, chunk->data, chunk->size);
if (!GBADeserialize(png_get_user_chunk_ptr(png), state)) {
free(state);
longjmp(png_jmpbuf(png), 1);
}
free(state);
return 1;
}
@ -252,6 +254,10 @@ static bool _loadPNGState(struct GBA* gba, struct VFile* vf) {
return false;
}
uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
if (!pixels) {
PNGReadClose(png, info, end);
return false;
}
PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs");
bool success = PNGReadHeader(png, info);