Skip to content

Commit

Permalink
Engine: fix crash when quitting while dialog options are on
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Jan 19, 2025
1 parent 60fc623 commit c382084
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Engine/ac/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,12 @@ void schedule_dialog_stop()
dialogOpts->Stop();
}

void shutdown_dialog_state()
{
dialogExec = {};
dialogOpts = {};
}

// end dialog manager


Expand Down
2 changes: 2 additions & 0 deletions Engine/ac/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ int run_dialog_option(int dlgnum, int dialog_choice, int sayChosenOption, bool r
bool handle_state_change_in_dialog_request(const char *apiname, int dlgreq_retval);
// Shedule dialog state to stop next time it receives a control
void schedule_dialog_stop();
// Disposes dialog state object(s)
void shutdown_dialog_state();

extern std::vector<ScriptDialog> scrDialog;
extern std::vector<DialogTopic> dialog;
Expand Down
7 changes: 7 additions & 0 deletions Engine/ac/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "gui/guitextbox.h"
#include "gui/guidialog.h"
#include "main/engine.h"
#include "main/game_run.h"
#include "media/audio/audio_system.h"
#include "media/video/video.h"
#include "platform/base/agsplatformdriver.h"
Expand Down Expand Up @@ -495,6 +496,12 @@ void free_do_once_tokens()
play.do_once_tokens.clear();
}

void shutdown_game_state()
{
// Try every possible game state that is represented by a global object
shutdown_dialog_state();
ShutGameWaitState();
}

// Free all the memory associated with the game
void unload_game()
Expand Down
2 changes: 2 additions & 0 deletions Engine/ac/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ void save_game_dialog2(int min_slot, int max_slot);
// Unconditionally display a built-in save game dialog
bool do_save_game_dialog(int min_slot, int max_slot);
void free_do_once_tokens();
// Shuts down game's running state objects
void shutdown_game_state();
// Free all the memory associated with the game
void unload_game();
void save_game(int slotn, const Common::String &descript, std::unique_ptr<Common::Bitmap> &&image = nullptr);
Expand Down
5 changes: 5 additions & 0 deletions Engine/main/game_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,11 @@ void SyncDrawablesState()
update_objects_scale();
}

void ShutGameWaitState()
{
restrict_until = {};
}

void update_polled_stuff()
{
if (want_exit) {
Expand Down
2 changes: 2 additions & 0 deletions Engine/main/game_run.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void UpdateCursorAndDrawables();
// Useful after a major game state change, such as loading new room, in case we expect
// that a render may occur before a normal game update is performed.
void SyncDrawablesState();
// Shuts down game's waiting state, if one is running right now.
void ShutGameWaitState();
// Gets current logical game FPS, this is normally a fixed number set in script;
// in case of "maxed fps" mode this function returns real measured FPS.
float get_game_fps();
Expand Down
3 changes: 1 addition & 2 deletions Engine/main/quit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ void quit(const char *quitmsg)

set_our_eip(9900);

set_our_eip(9016);

quit_stop_cd();
if (use_cdplayer)
platform->ShutdownCDPlayer();
Expand All @@ -209,6 +207,7 @@ void quit(const char *quitmsg)

// Release game data and unregister assets
quit_check_dynamic_sprites(qreason);
shutdown_game_state();
unload_game();
AssetMgr.reset();

Expand Down
4 changes: 2 additions & 2 deletions Engine/media/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static HError video_single_run(std::unique_ptr<VideoPlayer> video, const String
gl_Video->Begin();
while (gl_Video->Run());
gl_Video->End();
gl_Video.reset();
gl_Video = {};

return HError::None();
}
Expand Down Expand Up @@ -424,7 +424,7 @@ void video_single_resume()

void video_single_stop()
{
gl_Video.reset();
gl_Video = {};
}

void video_shutdown()
Expand Down

0 comments on commit c382084

Please sign in to comment.