Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cherry pick) Don't call GameSession::restart_level in the constructor #3115

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "supertux/game_session.hpp"

#include <cfloat>
#include <fmt/format.h>
#include <stdexcept>

#include "audio/sound_manager.hpp"
#include "control/input_manager.hpp"
Expand Down Expand Up @@ -151,7 +153,7 @@ GameSession::on_player_removed(int id)
return false;
}

int
void
GameSession::restart_level(bool after_death, bool preserve_music)
{
const PlayerStatus& currentStatus = m_savegame.get_player_status();
Expand Down Expand Up @@ -234,7 +236,7 @@ GameSession::restart_level(bool after_death, bool preserve_music)
m_currentsector = m_level->get_sector(spawnpoint->sector);
if (!m_currentsector)
{
throw std::runtime_error("Couldn't find sector '" + spawnpoint->sector + "' to spawn/respawn Tux.");
throw std::runtime_error(fmt::format("Couldn't find sector '{}' to spawn/respawn Tux.", spawnpoint->sector));
}
// Activate on either the spawnpoint (if set), or the spawn position.
if (spawnpoint->spawnpoint.empty())
Expand All @@ -247,9 +249,8 @@ GameSession::restart_level(bool after_death, bool preserve_music)
}
}
catch (std::exception& e) {
log_fatal << "Couldn't start level: " << e.what() << std::endl;
throw std::runtime_error(fmt::format("Couldn't start level: {}", e.what()));
swagtoy marked this conversation as resolved.
Show resolved Hide resolved
ScreenManager::current()->pop_screen();
return (-1);
}

if (m_levelintro_shown)
Expand Down Expand Up @@ -277,8 +278,6 @@ GameSession::restart_level(bool after_death, bool preserve_music)
it->set_time(it->get_time() - m_play_time);
it++;
}

return (0);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/game_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class GameSession final : public Screen,
std::string get_working_directory() const;
inline const std::string& get_level_file() const { return m_levelfile; }
inline bool has_active_sequence() const { return m_end_sequence; }
int restart_level(bool after_death = false, bool preserve_music = false);
void restart_level(bool after_death = false, bool preserve_music = false);

void toggle_pause();
void abort_level();
Expand Down
Loading