From a0671bc8a9d8586fbcc893bb3b6208e98b58bcc4 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 19 Jul 2019 19:57:11 +0300 Subject: [PATCH] Fix SGB save states --- bsnes/sfc/coprocessor/icd/serialization.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bsnes/sfc/coprocessor/icd/serialization.cpp b/bsnes/sfc/coprocessor/icd/serialization.cpp index 75eff3c8..d3a72770 100644 --- a/bsnes/sfc/coprocessor/icd/serialization.cpp +++ b/bsnes/sfc/coprocessor/icd/serialization.cpp @@ -3,13 +3,17 @@ auto ICD::serialize(serializer& s) -> void { auto size = GB_get_save_state_size(&sameboy); auto data = new uint8_t[size]; - s.array(data, size); - if(s.mode() == serializer::Load) { - GB_load_state_from_buffer(&sameboy, data, size); - } + if(s.mode() == serializer::Save) { GB_save_state_to_buffer(&sameboy, data); } + + s.array(data, size); + + if(s.mode() == serializer::Load) { + GB_load_state_from_buffer(&sameboy, data, size); + } + delete[] data; for(auto n : range(64)) s.array(packet[n].data);