Skip to content

[CRASHFIX] Stop vehicle missing frame check from causing crash by using typical part iteration loop. Optimize too. #3500

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

Merged
merged 2 commits into from
Oct 8, 2013
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,11 @@ void vehicle::json_load(picojson::value & parsed, game * g ) {
}
parray = NULL;
}
/* After loading, check if the vehicle is from the old rules and is missing
* frames. */
if ( savegame_loading_version < 11 ) {
add_missing_frames();
}
find_external_parts ();
find_exhaust ();
insides_dirty = true;
Expand Down
3 changes: 3 additions & 0 deletions savegame_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,9 @@ void vehicle::load_legacy(std::ifstream &stin) {
}
parts.push_back (new_part);
}
/* After loading, check if the vehicle is from the old rules and is missing
* frames. */
add_missing_frames();
find_external_parts ();
find_exhaust ();
insides_dirty = true;
Expand Down
21 changes: 12 additions & 9 deletions vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ void vehicle::load (std::ifstream &stin)
} else {
load_legacy(stin);
}

/* After loading, check if the vehicle is from the old rules and is missing
* frames. */
add_missing_frames();

}

/** Checks all parts to see if frames are missing (as they might be when
Expand All @@ -91,9 +86,9 @@ void vehicle::add_missing_frames()
{
//No need to check the same (x, y) spot more than once
std::set< std::pair<int, int> > locations_checked;
for(std::vector<vehicle_part>::iterator it = parts.begin(); it != parts.end(); it++) {
int next_x = it->mount_dx;
int next_y = it->mount_dy;
for (int i = 0; i < parts.size(); i++) {
int next_x = parts[i].mount_dx;
int next_y = parts[i].mount_dy;
std::pair<int, int> mount_location = std::make_pair(next_x, next_y);

if(locations_checked.count(mount_location) == 0) {
Expand All @@ -108,7 +103,15 @@ void vehicle::add_missing_frames()
}
if(!found) {
//No frame here! Install one.
install_part(next_x, next_y, "frame_vertical", -1, true);
vehicle_part new_part;
new_part.id = "frame_vertical";
new_part.mount_dx = next_x;
new_part.mount_dy = next_y;
new_part.hp = vehicle_part_types["frame_vertical"].durability;
new_part.amount = 0;
new_part.blood = 0;
new_part.bigness = 0;
parts.push_back (new_part);
}
}

Expand Down