From 5b62fbb355fe1283cb0786ac493373fe12208db9 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Thu, 29 Sep 2016 17:28:01 -0400 Subject: [PATCH] Fix spectator mode to work with the late-serialization workaround --- network/netplay/netplay.c | 2 +- network/netplay/netplay_spectate.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/network/netplay/netplay.c b/network/netplay/netplay.c index 1f6af43878..433b022288 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay.c @@ -721,7 +721,7 @@ static bool netplay_poll(void) /* WORKAROUND: The only reason poll_input is ignored in the first frame is * that some cores can't report state size until after the first frame. */ - if (netplay_data->self_frame_count > 0 || netplay_data->stall) + if (netplay_data->self_frame_count > 0 || netplay_data->stall || netplay_data->spectate.enabled) { /* Read Netplay input, block if we're configured to stall for input every * frame */ diff --git a/network/netplay/netplay_spectate.c b/network/netplay/netplay_spectate.c index e6dbbd8aac..a3b679c37b 100644 --- a/network/netplay/netplay_spectate.c +++ b/network/netplay/netplay_spectate.c @@ -36,6 +36,29 @@ **/ static bool netplay_spectate_pre_frame(netplay_t *netplay) { + /* WORKAROUND: We initialize the buffer states here as part of a workaround + * for cores that can't even core_serialize_size early. */ + if (netplay->self_frame_count == 0 && netplay->state_size == 0) + { + int i; + retro_ctx_size_info_t info; + + core_serialize_size(&info); + + netplay->state_size = info.size; + + for (i = 0; i < netplay->buffer_size; i++) + { + netplay->buffer[i].state = calloc(netplay->state_size, 1); + + if (!netplay->buffer[i].state) + { + netplay->savestates_work = false; + netplay->stall_frames = 0; + } + } + } + if (netplay_is_server(netplay)) { fd_set fds;