-
Notifications
You must be signed in to change notification settings - Fork 42
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
Don't access items in empty cache #2332
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2247,6 +2247,9 @@ void add_specialist_output( | |
// This is more than just an optimization. For governors that forbid | ||
// specialists, the cache may not be filled. | ||
if (count > 0) { | ||
// If there is a cache it must not be empty. | ||
fc_assert(!pcsoutputs || !pcsoutputs->empty()); | ||
|
||
output_type_iterate(stat_index) | ||
{ | ||
int amount = pcsoutputs | ||
|
@@ -2876,6 +2879,9 @@ void set_city_production(struct city *pcity, | |
* on, so shield waste will include shield bonuses. */ | ||
output_type_iterate(o) | ||
{ | ||
// If there is a cache it must not be empty. | ||
fc_assert(!pcwaste || !pcwaste->empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably go before the loop to avoid getting 6 messages every time. I think returning if the assert fails is fine, so use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
pcity->waste[o] = | ||
city_waste(pcity, o, pcity->prod[o] * pcity->bonus[o] / 100, nullptr, | ||
gov_centers, pcwaste ? &pcwaste->at(o) : nullptr); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fc_
asserts aren't fatal by default. Usefc_assert_action(condition, continue)
to skip this specialist, which is probably an ok fallback behavior:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented another solution, falling back to the old behaviour by setting the cache to
nullptr
if the assertion triggers. This makes sure, that the game will behave correctly. What do you think?