From 99b5ed92ed335c5211ed17381499d6589c321559 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Tue, 13 Sep 2016 20:35:10 -0400 Subject: [PATCH] other should always be <= both real AND self. Before this fix, it was possible (albeit unlikely) for the remote to get so far ahead of us that they actually overwrote our own current data :) --- network/netplay/netplay_net.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/network/netplay/netplay_net.c b/network/netplay/netplay_net.c index 6458f1e412..10f00e2054 100644 --- a/network/netplay/netplay_net.c +++ b/network/netplay/netplay_net.c @@ -70,7 +70,8 @@ static void netplay_net_post_frame(netplay_t *netplay) /* Skip ahead if we predicted correctly. * Skip until our simulation failed. */ - while (netplay->other_frame_count < netplay->read_frame_count) + while (netplay->other_frame_count < netplay->read_frame_count && + netplay->other_frame_count < netplay->self_frame_count) { const struct delta_frame *ptr = &netplay->buffer[netplay->other_ptr]; @@ -83,7 +84,8 @@ static void netplay_net_post_frame(netplay_t *netplay) } /* Now replay the real input if we've gotten ahead of it */ - if (netplay->other_frame_count < netplay->read_frame_count) + if (netplay->other_frame_count < netplay->read_frame_count && + netplay->other_frame_count < netplay->self_frame_count) { retro_ctx_serialize_info_t serial_info; @@ -120,16 +122,14 @@ static void netplay_net_post_frame(netplay_t *netplay) netplay->replay_frame_count++; } - /* For the remainder of the frames up to the read count, we can use the real data */ - while (netplay->replay_frame_count < netplay->read_frame_count) + if (netplay->read_frame_count < netplay->self_frame_count) { - retro_assert(netplay->buffer[netplay->replay_ptr].have_remote); - netplay->replay_ptr = NEXT_PTR(netplay->replay_ptr); - netplay->replay_frame_count++; + netplay->other_ptr = netplay->read_ptr; + netplay->other_frame_count = netplay->read_frame_count; + } else { + netplay->other_ptr = netplay->self_ptr; + netplay->other_frame_count = netplay->self_frame_count; } - - netplay->other_ptr = netplay->read_ptr; - netplay->other_frame_count = netplay->read_frame_count; netplay->is_replay = false; }