Rebuild active_item cache for vehicles after refresh #60952
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Bugfixes "Some items taken out of fridges rot immediately"
Purpose of change
Fixes #58824
Describe the solution
After we modified
vehicle::refresh()
to add/remove fake parts, it seems to have started causing issues with theactive_item
cache for vehicles. More information in my comment here. TL;DR,vehicle::refresh
causedactive_items
to become empty, which caused items inside the vehicle not to be processed for rot etc.It seems we need to refresh the
active_item
cache as part ofvehicle::refresh
now based on this. So I made the following changes:vehicle::refresh_active_item_cache
to encapsulate the logic for setting upactive_items
vehicle::refresh_active_item_cache
method at the end of thevehicle::refresh
methodactive_item
cache directly invehicle::deserialize
- this method callsvehicle::refresh
which handles this now by callingvehicle::refresh_active_item_cache
.Describe alternatives you've considered
active_item
cache and this isn't the right solution. At the very least I hope my naive attempt at fixing this might serve to push someone with a bit more context towards the right solution.Testing
Using the debug stuff described here I verified that after applying the changes, items in fridges were no longer frozen in time after a save/load, and had rot values updated as expected while waiting nearby.