Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when loading a savegame where "savegame actor arraylen < LDB actor arraylen" #1345

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/game_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ void Game_Actors::Init() {
}

void Game_Actors::Fixup() {
for (size_t i = 1; i < data.size(); ++i) {
GetActor(i)->Fixup();
}

// Ensure actor save data and LDB actors has correct size
if (Main_Data::game_data.actors.size() != data.size()) {
size_t save_actor_size = Main_Data::game_data.actors.size();

Output::Warning("Actor array size doesn't match Savegame actor array size (%d != %d)",
Main_Data::game_data.actors.size(), data.size());
data.size(), save_actor_size);

Main_Data::game_data.actors.resize(data.size());

// When the save data size is smaller than the LDB size set the additional actors to nullptr.
// GetActor will copy the actor data to the savegame data next time it is invoked.
if (save_actor_size < data.size()) {
std::fill(data.begin() + save_actor_size, data.end(), nullptr);
}
}

for (size_t i = 1; i < data.size(); ++i) {
GetActor(i)->Fixup();
}
}

Expand Down