Skip to content

Commit

Permalink
Fix: thread safety issue during exiting the game (#9380)
Browse files Browse the repository at this point in the history
_exit_game is read by the draw-thread to know when to exit, but
most of the time written by the game-thread.
  • Loading branch information
TrueBrain committed Jun 17, 2021
1 parent 281a65b commit c12a152
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gfx.cpp
Expand Up @@ -41,7 +41,7 @@ bool _right_button_down; ///< Is right mouse button pressed?
bool _right_button_clicked; ///< Is right mouse button clicked?
DrawPixelInfo _screen;
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
bool _exit_game;
std::atomic<bool> _exit_game;
GameMode _game_mode;
SwitchMode _switch_mode; ///< The next mainloop command.
PauseMode _pause_mode;
Expand Down
3 changes: 2 additions & 1 deletion src/openttd.h
Expand Up @@ -10,6 +10,7 @@
#ifndef OPENTTD_H
#define OPENTTD_H

#include <atomic>
#include "core/enum_type.hpp"

/** Mode which defines the state of the game. */
Expand Down Expand Up @@ -52,7 +53,7 @@ enum DisplayOptions {

extern GameMode _game_mode;
extern SwitchMode _switch_mode;
extern bool _exit_game;
extern std::atomic<bool> _exit_game;
extern bool _save_config;

/** Modes of pausing we've got */
Expand Down

0 comments on commit c12a152

Please sign in to comment.