Skip to content

Commit

Permalink
fix UB in story_viewer
Browse files Browse the repository at this point in the history
previously the first image timer would not be cleared when the user restarted
the part, which in particular caused UB if the story_viewer was closed
before all timers have finished.

fixes #3838 fixes #3837
  • Loading branch information
gfgtdf committed Oct 6, 2019
1 parent adbcbd0 commit d7a0fec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/gui/dialogs/story_viewer.cpp
Expand Up @@ -67,14 +67,19 @@ story_viewer::story_viewer(const std::string& scenario_name, const config& cfg_p
update_current_part_ptr();
}

story_viewer::~story_viewer()
void story_viewer::clear_image_timer()
{
if(timer_id_ != 0) {
remove_timer(timer_id_);
timer_id_ = 0;
}
}

story_viewer::~story_viewer()
{
clear_image_timer();
}

void story_viewer::pre_show(window& window)
{
window.set_enter_disabled(true);
Expand Down Expand Up @@ -294,7 +299,8 @@ void story_viewer::display_part(window& window)
text_label.set_label(part_text);

begin_fade_draw(true);

// if the previous page was skipped, it is possible that we already have a timer running.
clear_image_timer();
//
// Floating images (handle this last)
//
Expand Down
2 changes: 2 additions & 0 deletions src/gui/dialogs/story_viewer.hpp
Expand Up @@ -52,6 +52,8 @@ class story_viewer : public modal_dialog
/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;

void clear_image_timer();

void update_current_part_ptr();

void display_part(window& window);
Expand Down

0 comments on commit d7a0fec

Please sign in to comment.