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

Fix #39914 (Random error) #40098

Merged
merged 1 commit into from
May 3, 2020
Merged

Fix #39914 (Random error) #40098

merged 1 commit into from
May 3, 2020

Conversation

BevapDin
Copy link
Contributor

@BevapDin BevapDin commented May 3, 2020

SUMMARY: None

After encountering this myself (in hindsight it's probably caused by a corpse being revived and subsequently being removed, the item in question was a corpse). The relevant information from gdb:

(gdb) print removed_items.front()
$11 = (item *) 0x1b0df490
(gdb) print this
$12 = (item * const) 0x1b0df490

Note that the games effectively calls this->remove_item(this), which can not work.

item::visit_items invokes the given callback for this as well, and therefor this appears in the list of item to be removed at the end.

Fixes #39914, I suspect it also fixes #39402 as it has the same backtrace (item::process calling visitable::remove_item).

The code calls `visitable::visit_items` and adds all items to be removed as reported by the lambda to the vector and later calls `visitable::remove_item` for all those listed items. But `visit_items` will visit `this` as well. So the vector ends up containing `this`, which is subsequently given to `remove_item`, which complains (correctly) that `this` is not contains in `this`.
@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` labels May 3, 2020
Copy link
Contributor

@ifreund ifreund left a comment

Choose a reason for hiding this comment

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

Thanks!

@ifreund ifreund merged commit 3f4e86a into CleverRaven:master May 3, 2020
@kevingranade
Copy link
Member

This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there:

https://discourse.cataclysmdda.org/t/experimental-bugs-tried-removing-item-from-object-which-did-not-contain-it/23447/13

fengjixuchui added a commit to fengjixuchui/Cataclysm-DDA that referenced this pull request May 3, 2020
@Termineitor244
Copy link
Contributor

Thanks for this! Indeed, it was mainly a problem with zombie corpses reanimating.

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`
Projects
None yet
4 participants