Skip to content

Commit 6b41236

Browse files
committed
Fixed desync bug. The characters were unable to reconcile in some cases.
1 parent a5c65f4 commit 6b41236

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

core/peer_networked_controller.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ void DollController::copy_controlled_objects_snapshot(
16731673
}
16741674

16751675
const std::vector<NameAndVar> *vars = p_snapshot.get_object_vars(object_data->get_net_id());
1676-
ENSURE_CONTINUE_MSG(vars, "The snapshot didn't contain the object: " + object_data->get_net_id() + ". If this error spams for a long period (5/10 seconds), it's a bug.");
1676+
ENSURE_CONTINUE_MSG(vars, "[FATAL] The snapshot didn't contain the object: " + object_data->get_net_id() + ". If this error spams for a long period (1/2 seconds) or never recover, it's a bug since.");
16771677

16781678
snap->data.simulated_objects.push_back(object_data->get_net_id());
16791679

@@ -1691,11 +1691,12 @@ void DollController::copy_controlled_objects_snapshot(
16911691
}
16921692

16931693
FrameIndex DollController::fetch_checkable_snapshot(DollSnapshot *&r_client_snapshot, DollSnapshot *&r_server_snapshot) {
1694+
clear_previously_generated_client_snapshots();
1695+
16941696
for (auto client_snap_it = client_snapshots.rbegin(); client_snap_it != client_snapshots.rend(); client_snap_it++) {
16951697
if (client_snap_it->doll_executed_input != FrameIndex::NONE) {
1696-
#ifdef DEBUG_ENABLED
16971698
ASSERT_COND_MSG(client_snap_it->doll_executed_input <= current_input_buffer_id, "All the client snapshots are properly cleared when the `current_input_id` is manipulated. So this function is impossible to trigger. If it does, there is a bug on the `clear_previously_generated_client_snapshots`.");
1698-
#endif
1699+
16991700
auto server_snap_it = VecFunc::find(server_snapshots, client_snap_it->doll_executed_input);
17001701
if (server_snap_it != server_snapshots.end()) {
17011702
r_client_snapshot = &(*client_snap_it);

scene_synchronizer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "scene_synchronizer.h"
32

43
#include "core/config/project_settings.h"

tests/test_doll_simulation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,17 @@ void test_simulation_with_wrong_input() {
635635
test.assert_positions(NS::FrameIndex{ 0 }, NS::FrameIndex{ 0 });
636636

637637
// 2. Now introduce a desync on the server.
638-
for (int test_count = 0; test_count < 4; test_count++) {
638+
for (int test_count = 0; test_count < 5; test_count++) {
639639
for (int i = 0; i < 3; i++) {
640-
const NS::FrameIndex c1_assert_after = server_controller_1->get_current_frame_index() + 15;
641-
const NS::FrameIndex c2_assert_after = server_controller_2->get_current_frame_index() + 15;
640+
const NS::FrameIndex c1_assert_after = server_controller_1->get_current_frame_index() + 20;
641+
const NS::FrameIndex c2_assert_after = server_controller_2->get_current_frame_index() + 20;
642642
const int c1_desync_vec_size = test.peer1_desync_detected.size();
643643
const int c2_desync_vec_size = test.peer2_desync_detected.size();
644644

645645
test.controlled_1_serv->modify_input_on_next_frame = true;
646646
test.controlled_2_serv->modify_input_on_next_frame = true;
647647
// Process 50 frames and ensure it recovers.
648-
test.do_test(50);
648+
test.do_test(75);
649649

650650
// Ensure there was a desync.
651651
ASSERT_COND(test.peer1_desync_detected.size() > c1_desync_vec_size);

0 commit comments

Comments
 (0)