Prevent wesnoth from crashing after campaign credits (#8235)

Fixes #7395
This commit is contained in:
Pentarctagon 2024-01-13 11:15:50 -06:00 committed by GitHub
parent 7c4ac03be2
commit 987827b475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View file

@ -36,6 +36,7 @@ outro::outro(const game_classification& info)
: modal_dialog(window_id())
, text_()
, current_text_()
, text_index_(0)
, duration_(info.end_text_duration)
, fade_step_(0)
, fading_in_(true)
@ -84,7 +85,7 @@ outro::outro(const game_classification& info)
}
}
current_text_ = text_.begin();
current_text_ = text_[0];
if(!duration_) {
duration_ = 3500; // 3.5 seconds
@ -94,11 +95,16 @@ outro::outro(const game_classification& info)
void outro::pre_show(window& window)
{
window.set_enter_disabled(true);
window.get_canvas(0).set_variable("outro_text", wfl::variant(*current_text_));
window.get_canvas(0).set_variable("outro_text", wfl::variant(current_text_));
}
void outro::update()
{
// window doesn't immediately close, keep returning until it does
if(text_index_ >= text_.size()) {
return;
}
/* If we've faded fully in...
*
* NOTE: we want fading to take around half a second. Given this function runs about every 3 frames, we
@ -118,16 +124,16 @@ void outro::update()
// If we've faded fully out...
if(!fading_in_ && fade_step_ < 0) {
std::advance(current_text_, 1);
// ...and we've just showed the last text bit, close the window.
if(current_text_ == text_.end()) {
text_index_++;
if(text_index_ >= text_.size()) {
window::close();
return;
}
current_text_ = text_[text_index_];
// ...else show the next bit.
window_canvas.set_variable("outro_text", wfl::variant(*current_text_));
window_canvas.set_variable("outro_text", wfl::variant(current_text_));
fading_in_ = true;
fade_step_ = 0;

View file

@ -48,10 +48,9 @@ private:
virtual void post_show(window& window) override;
void draw_callback();
std::vector<std::string> text_;
std::vector<std::string>::iterator current_text_;
std::string current_text_;
std::size_t text_index_;
unsigned int duration_;
int fade_step_;

View file

@ -221,8 +221,8 @@ public:
/**
* Requests to close the window.
*
* At the moment the request is always honored but that might change in the
* future.
* This request is not always honored immediately, and so callers must account for the window remaining open.
* For example, when overriding draw_manager's update() method.
*/
void close()
{