Skip to content

Commit

Permalink
BevyRenet: fix disconnect_on_exit not being called
Browse files Browse the repository at this point in the history
Call disconnect_on_exit on "Last" schedule, this mean it will handle the cases of exit_on_primary_closed/exit_on_all_closed or user submit AppExit events
  • Loading branch information
lucaspoffo committed Nov 9, 2024
1 parent 042ede9 commit f793ce6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
20 changes: 18 additions & 2 deletions bevy_renet/src/netcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ impl Plugin for NetcodeServerPlugin {

app.add_systems(
PostUpdate,
(Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit)
Self::send_packets
.in_set(RenetSend)
.run_if(resource_exists::<NetcodeServerTransport>)
.run_if(resource_exists::<RenetServer>),
);

app.add_systems(
Last,
Self::disconnect_on_exit
.run_if(resource_exists::<NetcodeServerTransport>)
.run_if(resource_exists::<RenetServer>),
);
Expand Down Expand Up @@ -71,7 +79,15 @@ impl Plugin for NetcodeClientPlugin {
);
app.add_systems(
PostUpdate,
(Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit)
Self::send_packets
.in_set(RenetSend)
.run_if(resource_exists::<NetcodeClientTransport>)
.run_if(resource_exists::<RenetClient>),
);

app.add_systems(
Last,
Self::disconnect_on_exit
.run_if(resource_exists::<NetcodeClientTransport>)
.run_if(resource_exists::<RenetClient>),
);
Expand Down
14 changes: 12 additions & 2 deletions bevy_renet/src/steam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ impl Plugin for SteamServerPlugin {

app.add_systems(
PostUpdate,
(Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit).run_if(resource_exists::<RenetServer>),
Self::send_packets.in_set(RenetSend).run_if(resource_exists::<RenetServer>),
);

app.add_systems(Last, Self::disconnect_on_exit.run_if(resource_exists::<RenetServer>));
}
}

Expand Down Expand Up @@ -78,7 +80,15 @@ impl Plugin for SteamClientPlugin {
);
app.add_systems(
PostUpdate,
(Self::send_packets.in_set(RenetSend), Self::disconnect_on_exit)
Self::send_packets
.in_set(RenetSend)
.run_if(resource_exists::<SteamClientTransport>)
.run_if(resource_exists::<RenetClient>),
);

app.add_systems(
Last,
Self::disconnect_on_exit
.run_if(resource_exists::<SteamClientTransport>)
.run_if(resource_exists::<RenetClient>),
);
Expand Down

0 comments on commit f793ce6

Please sign in to comment.