-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Help modders deal with object invalidation #14769
base: master
Are you sure you want to change the base?
Conversation
Adding a method does not qualify as bugfix, but the first two commits would be useful for 5.9 so how about splitting it?
But the function already skips invalid objects, so this is only convenience, right? |
The current function returns a table of objects. Some of these objects may be invalidated between building the table and reaching the object in the for loop |
Ah, that's easy to miss. The docs should explain the benefit of the new functions more clearly. |
I agree that it may be debatable whether the new iterator variants (and I can split if you want me to, though. |
After finding out that it's not just a simple helper but rather fixes an easy to miss edge case I'm okay with keeping it as a bug fix. |
Why not simply overwrite the current get functions? Like, I can't think of any useful case where mods want to iterate invalid objects as well. On the contrary, I always have to put checks in my for loops in order to avoid crashes |
Their API unfortunately makes this infeasible: They return a "list" of object refs. Now the edge case happens when you do something like this, for example: for _, obj in ipairs(minetest.get_objects_inside_radius(...)) do
obj:punch(...)
end Because punching an object can invalidate other objects in the list (such as children) via side effects. The problem is that these objects are already in the table, so there's no (proper) way to get rid of them after the fact. They will be visited in the traversal. With an iterator, this becomes cleaner, and the iterator can now check for and skip invalid objects. But this obviously requires modders to use the iterator rather than the table variant, hence is a "breaking" change and requires the addition of a new function which does the right thing. |
Co-authored-by: sfan5 <[email protected]>
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.
Fine by me.
Wouldn't this fix the ghost entities issue completely? |
Ultimately, I don't know. It fixes ghost entity issues related to this mistake, if the API is used properly. I would say it would probably make the issue a "possible close" under suspicion that this is the (main?) root cause for the issue. I can't rule out the possibility that there are other places where "ghost entities" may appear, though, i.e. that there is an underlying bug not fixed by this. |
Implements part of what I have outlined in #14687 (related: #13297):
is_valid
to idiomatically check for object validity.get_objects_(inside_radius|in_area)
, which skip invalid objects (and are also more convenient to use).