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

Space bodies deferred addition #5648

Merged

Conversation

JonBooth78
Copy link
Contributor

Fix the undefined behaviour when addiing bodies during the update loops that iterate through them

The undefined behaviour comes because when we add an item to the vector, it could have to reallocate to grow the backing storage and therefore the end iterator becomes potentially invalid.

Defer adding bodies until the end of an Space update tick.

A few game related scenarios (emerging from hyperspace, saving a game and loading a game) require this update to be invoked too.

I've been playing with this locally for a while and have yet to find any new issues.

…ps that iterate through them

The undefined behaviour comes because when we add an item to the vector, it could have to reallocate to grow the backing storage and therefore the end iterator becomes potentially invalid.

Defer adding bodies until the end of an Space update tick.

A few game related scenarios (emerging from hyperspace, saving a game and loading a game) require this update to be invoked too.
@JonBooth78 JonBooth78 force-pushed the space-bodies-deferred-addition branch from c55f205 to 10d878a Compare October 16, 2023 23:29
@sturnclaw
Copy link
Member

Hey, I'd almost forgotten about this one! Good work, the code looks clean and I'll give it a quick spin but I don't anticipate any problems.

@sturnclaw sturnclaw merged commit 9f10aa2 into pioneerspacesim:master Oct 29, 2023
4 checks passed
@JonBooth78 JonBooth78 deleted the space-bodies-deferred-addition branch February 3, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants