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

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

swagtoy
Copy link

@swagtoy swagtoy commented Nov 29, 2024

This stops testing (on the "Test from here")/the title screen (yes, the title screen) from reparsing the level by simply changing the usage pattern of the GameSession constructor.

Cherry picked from commit swagtoy@0d25b71 upon the request of Vankata.

This stops testing/the title screen (yes, the title screen) from
reparsing the level by simply changing the usage pattern of the
TitleScreen.

(Cherry picked from swagtoy/supertux:editor2)
@swagtoy
Copy link
Author

swagtoy commented Nov 29, 2024

wait hold on there's a regression where you can control Tux from the title screen

@swagtoy
Copy link
Author

swagtoy commented Nov 29, 2024

Okay, seems to work!

Later i'll actually end up probably creating an start_game() function, but this will unfortunately be part of the Level editor PR for now as I just don't have the time to cherry pick stuff and fix it only to stub my foot later.

@swagtoy swagtoy changed the title (cherry pick) Don't call GameSession::restart_level in the constructor [no squash] (cherry pick) Don't call GameSession::restart_level in the constructor Nov 29, 2024
src/supertux/levelset_screen.cpp Outdated Show resolved Hide resolved
src/supertux/game_session.cpp Show resolved Hide resolved
src/supertux/title_screen.cpp Outdated Show resolved Hide resolved
@swagtoy swagtoy changed the title [no squash] (cherry pick) Don't call GameSession::restart_level in the constructor [NO SQUASH] (cherry pick) Don't call GameSession::restart_level in the constructor Nov 29, 2024
@swagtoy
Copy link
Author

swagtoy commented Nov 29, 2024

Seems good now. I did test some things and it doesn't crash and burn. Any final words?

@Vankata453
Copy link
Member

src/supertux/game_session.cpp:253:5: style: Statements following 'throw' will never be executed. [unreachableCode]
    ScreenManager::current()->pop_screen();
    ^

src/supertux/levelset_screen.cpp Show resolved Hide resolved
@@ -354,10 +354,13 @@ WorldMapSector::update(float dt_sec)
Vector shrinkpos = Vector(level_->get_pos().x + 16 - m_camera->get_offset().x,
level_->get_pos().y + 8 - m_camera->get_offset().y);
std::string levelfile = m_parent.m_levels_path + level_->get_level_filename();

auto gamesession = std::make_unique<GameSession>(levelfile, m_parent.m_savegame, &level_->get_statistics());
gamesession->restart_level();
Copy link
Member

@Vankata453 Vankata453 Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can put a try/catch here so the game doesn't crash if level loading fails. You can then put the pop_screen() there in catch instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants