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

Prevent crashes and bad behavior when vehicle updates invalidate the vehicle list #31348

Merged
merged 2 commits into from
Jun 11, 2019

Conversation

kevingranade
Copy link
Member

Summary

SUMMARY: None

Purpose of change

The previous change #31330 had a logic error in that the list returned by map::get_vehicle() is invalidated in several situations, which could have lead to failing to update vehicles, or dereferencing orphaned pointers.

Describe the solution

Have movement methods return nullptr when the vehicle they are updating may have invalidated the list, either by being destroyed or by damaging another vehicle. Then when the calling function detects a returned nullptr, refresh the vehicle list.

Describe alternatives you've considered

All of this code needs to be seriously rethought, but this adresses the issue for now.

@kevingranade kevingranade changed the title Return a nullptr when vehicle is invalidated Prevent crashes and bad behavior when vehicle updates invalidate the vehicle list Jun 11, 2019
Copy link
Contributor

@mlangsdorf mlangsdorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty obvious when you think about it.

@ifreund ifreund added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Vehicles Vehicles, parts, mechanics & interactions labels Jun 11, 2019
@ZhilkinSerg ZhilkinSerg merged commit 552cdd0 into master Jun 11, 2019
@kevingranade kevingranade deleted the kevingranade-fix-vehicle-list-invalidation branch July 8, 2019 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants