Skip to content

Commit c85040e

Browse files
authored
prevent a crash on game exit (#4507)
When `mission_campaign_clear()` is called, all persistent SEXP nodes (those used by the campaign) are marked as non-persistent. When `sexp_shutdown()` was moved in #4503, this caused `Sexp_nodes` to be nullptr when the campaign was cleared, which caused a crash. This reorders the shutdown functions to prevent the crash.
1 parent a16be86 commit c85040e

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

freespace2/freespace.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6684,19 +6684,6 @@ void game_shutdown(void)
66846684
gr_flip();
66856685
}
66866686

6687-
// Free SEXP resources
6688-
sexp_shutdown();
6689-
6690-
// Free the scripting resources of the new UI first
6691-
scpui::shutdown_scripting();
6692-
6693-
// Everything after this should be done without scripting so we can free those resources here. By this point, all things that hold Lua References must be destroyed (such as Lua SEXPs)
6694-
Script_system.Clear();
6695-
6696-
// Deinitialize the new UI system, needs to be done after scripting shutdown to make sure the resources were
6697-
// released properly
6698-
scpui::shutdown();
6699-
67006687
// if the player has left the "player select" screen and quit the game without actually choosing
67016688
// a player, Player will be nullptr, in which case we shouldn't write the player file out!
67026689
if (!(Game_mode & GM_STANDALONE_SERVER) && (Player!=nullptr) && !Is_standalone){
@@ -6732,7 +6719,6 @@ void game_shutdown(void)
67326719

67336720
scoring_close();
67346721

6735-
67366722
stars_close(); // clean out anything used by stars code
67376723

67386724
// the menu close functions will unload the bitmaps if they were displayed during the game
@@ -6742,6 +6728,19 @@ void game_shutdown(void)
67426728
// free left over memory from table parsing
67436729
player_tips_close();
67446730

6731+
6732+
// more fundamental shutdowns begin here ----------
6733+
6734+
sexp_shutdown(); // Free SEXP resources
6735+
6736+
scpui::shutdown_scripting(); // Free the scripting resources of the new UI first
6737+
6738+
Script_system.Clear(); // Everything after this should be done without scripting so we can free those resources here.
6739+
// By this point, all things that hold Lua References must be destroyed (such as Lua SEXPs)
6740+
6741+
scpui::shutdown(); // Deinitialize the new UI system, needs to be done after scripting shutdown to make sure the resources were released properly
6742+
6743+
67456744
control_config_common_close();
67466745
io::joystick::shutdown();
67476746

@@ -6780,7 +6779,6 @@ void game_shutdown(void)
67806779
}
67816780

67826781
lcl_xstr_close();
6783-
67846782
}
67856783

67866784
// game_stop_looped_sounds()

0 commit comments

Comments
 (0)