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
Script API: Check that SAOs are still usable before attempting to use them #9390
Conversation
I'm now getting crashes from nil-values returned from I'm opening an issue if it is caused by this.. |
Hm, well this fix has the side effect that the ObjectRefs that were buggy before are now entirely non-functionality with all relevant methods returning It would be possible to work around this in the affected mods, but that would be incorrect. |
No, not in that time-frame, the patch was only active for about 15 minutes.. |
I'm definitely glad to hear that there is now fully consistent behavior for all methods of a freed ObjectRef. Perhaps it might be worth mentioning that point in the documentation. |
Hmm... I'm seeing this too with various mods that use mobs_redo. Perhaps we should undo this one (I agree it's correct behavior, yet, there are mods that are broken by this). |
I believe the ultimately better outcome is to get mods fixed quickly right now instead of turning it into a soft warning and getting mods fixed sometime somewhen (or never). Also, has anyone noticed errors with a mod other than |
Not yet, no, but i'm guessing this will be a mine-field... 😖 I fixed the |
I'm also not 100% sure the change has the behavior we want. I haven't looked closely at this part of the code, is there a risk of accessing freed memory? |
I have to wonder how this change broke the 3d_armor mod. I looked at the PR linked above and don't see any changes dealing with ObjectRefs, just a lot of renaming of variables. Perhaps I missed something. |
I get that it's more convenient here but why would we? The mod has just asked to delete the object, it should cease to exist.
There isn't and unlike the reported bug (#9387) for players I don't think using entities after their removal could crash anything either. |
I can sort of see @lhofhansl's point. It might be more intuitive that calls to obj:remove() only add the object to a queue to be removed. But the object is not actually removed from the environment until control is returned back to the environment at the conclusion of the server step. (Personally, I thought that's how it already worked on the CPP side, but I suppose I'm recalling wrong). Nevertheless, I must agree with @sfan5, that if an object is removed, then rightfully it should cease to exist at that point going forward. Mod developers should properly document their own API so that there is no risk of objects still being referenced after removal. Or at least they should provide some kind of callback mechanism so that other mods can be notified of a pending removal. These are mod-specific implementation details, and technically shouldn't be the responsibility of the engine. |
Upon further reflection I disagree. I vote for reverting... Perhaps with commenting what the delete method means. |
If an object is removed from the set of active objects, then what type of object is it at that point? Its not a LuaEntitySAO nor is it a PlayerSAO. Perhaps it is a DeletedServerObj? Shouldn't there be documentation on the API for this new class of DeletedServerObjs? |
Well not exactly. The mod has marked the object for removal, the earliest point at which that can happen is the current server step (after all step callbacks have run).
Would you want this reverted for players and Luaentities or just Luaentities?
The same it always was, the type does not change. |
Just Luaentities, I think - assuming others agree obviously. |
So should we revert the Luaentities part of this? |
My vote is still no, I don't know the opinions of other coredevs. |
My vote is still yes :) Perhaps some other core devs could weigh in. And for the record I have reverted that part here, and seen no issues. |
There were already warnings when invalid/deleted objects were accessed. This PR "only" enforced the object lifespan which now became an issue in mods that relied on it. |
Honestly I'd rather get rid of the warnings then. The object is not deleted, it's still there, just not in the set of currently active object anymore. That's easy to explain, easy to understand, and easy to use in mods. We do the same in core. The object is still there, references are not set to null (not possible in C++ anyway) and there's an is_gone method. Can't do obj:is_valid() if you pull the rug from underneath by returning a null-reference, right? |
fixes #8587, fixes #9387
To do
This PR is a Ready for Review.
Q: Should this print a warning so the mod this happened in can be investigated?(not necessary)