Skip to content

Commit

Permalink
MP Manager: avoid setting singleton ptr until connection is established
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 7, 2021
1 parent 1f7a0e2 commit cd120f5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -160,9 +160,6 @@ mp_manager::mp_manager(const std::optional<std::string> host)
, state()
, lobby_info(::installed_addons())
{
assert(!manager);
manager = this;

state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;

if(host) {
Expand Down Expand Up @@ -214,6 +211,11 @@ mp_manager::mp_manager(const std::optional<std::string> host)
received_initial_gamelist.get_future().wait();
});
}

// Avoid setting this until the connection has been fully established. open_connection may throw,
// in which case we don't want to point to an object instance that has not properly connected.
assert(!manager);
manager = this;
}

std::unique_ptr<wesnothd_connection> mp_manager::open_connection(std::string host)
Expand Down

0 comments on commit cd120f5

Please sign in to comment.