AGS: Create a room placeholder to avoid crashes in game_start script

From upstream f3a6b65a80987f9fe993f5449538eb98a86c6353
This commit is contained in:
Paul Gilbert 2022-03-23 21:46:52 -07:00
parent ee119e9611
commit 5b56aecee4
4 changed files with 16 additions and 0 deletions

View File

@ -937,6 +937,16 @@ void new_room(int newnum, CharacterInfo *forchar) {
load_new_room(newnum, forchar);
}
void set_room_placeholder() {
_GP(thisroom).InitDefaults();
std::shared_ptr<Bitmap> dummy_bg(new Bitmap(1, 1, 8));
_GP(thisroom).BgFrames[0].Graphic = dummy_bg;
_GP(thisroom).HotspotMask = dummy_bg;
_GP(thisroom).RegionMask = dummy_bg;
_GP(thisroom).WalkAreaMask = dummy_bg;
_GP(thisroom).WalkBehindMask = dummy_bg;
}
int find_highest_room_entered() {
int qq, fndas = -1;
for (qq = 0; qq < MAX_ROOMS; qq++) {

View File

@ -52,6 +52,9 @@ void save_room_data_segment();
void unload_old_room();
void load_new_room(int newnum, CharacterInfo *forchar);
void new_room(int newnum, CharacterInfo *forchar);
// Sets up a placeholder room object; this is used to avoid occasional crashes
// in case an API function was called that needs to access a room, while no real room is loaded
void set_room_placeholder();
int find_highest_room_entered();
void first_room_initialization();
void check_new_room();

View File

@ -493,6 +493,8 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
// load the room the game was saved in
if (_G(displayed_room) >= 0)
load_new_room(_G(displayed_room), nullptr);
else
set_room_placeholder();
update_polled_stuff_if_runtime();

View File

@ -73,6 +73,7 @@ void start_game_load_savegame_on_startup() {
}
void start_game() {
set_room_placeholder();
set_cursor_mode(MODE_WALK);
_GP(mouse).SetPosition(Point(160, 100));
newmusic(0);