-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[3.x] Clear freed RIDs to fix disappearing meshes and id_map errors #54650
Conversation
I haven't examined in great details the VisualServer multithread wrapping / queue system as it contains a bunch of macro magic, but as far as I understand it, the I'm sure RandomShaper will be more familiar but to me it seems there is a potential danger of the ordering not being as expected:
Server code
Whereas with the existing system of passing the RID by value this danger is avoided. This could easily happen if a RID is used e.g. as a local variable. EDIT : All that said I'm not super familiar with RIDs (having just treated them like black boxes 😁 ), I'm having a look now. Ahh seeing that they actually do have a shared Second thing
Overall the RIDs in 3.x do look a bit error prone in terms of lifetime and validity, and I wonder why they weren't implemented as handles which are usually better in this regard, or at least handles with pointers that can be refreshed on demand and checked for validity etc. Maybe handles will have threading overhead anyway because in the Godot 'free-for-all' everytime you need to get / check one, you strictly speaking need to check for race conditions etc where something else has freed the object. I gather they have been changed quite a bit in 4.x, I wonder if any of the improvement ideas there could be backported. Irrespective of whether we keep with pointers in 3.x, having a EDIT: Yes on looking at 4.x, it looks like it is using pretty much handles, with a pool ID and a counter. I don't think this would be a big deal to get working in 3.x. See what @RandomShaper thinks. |
Just to keep up to date on this, I've discussed this with @RandomShaper and I'm trying out an implementation in 3.x with handles. This may end up being a better approach for RIDs overall in 3.x (similar to 4.x), or for just for bug finding in a specific build.. we'll know better soon, but don't spend too much time on this in the meantime. What would be useful though if you are interested is if you can track down the bugs in the spatial editor and do a fix PR for these only. This will be useful whatever approach we use for the RIDs, and it's good practice anyway to have one fix per PR (as is there seems to be two things in this PR). |
3e90b55
to
7778b74
Compare
@lawnjelly has rewritten RID to use handles as is done in 4.0 with PR #54907. Once that PR is merged, I'll redo this PR to address the other issues in VisualServer and SpatialEditor (# 3 in OP, 1,2,4 are replaced.). |
@tinmanjuggernaut It's not visible to me either, I guess it wasn't sent. Maybe it's in a pending review? |
@akien-mga It does say "Pending" but I have no option to have it not pend. @lawnjelly Here is my comment: The old code freed every grid_instance and grid, every tick, regardless of whether they were in use or not, and valid or not. Now it only considers the ones that are enabled, using the same wonky iteration scheme defined in Where the RIDs are created in the two paragraphs here: |
Ah sorry for confusion, it may be some moderation thing just until your first PR is merged, something like that. 🙂 I'm not sure the So I would go for simply setting to NULL here, and we can evaluate improvements in another PR? As an aside the whole grid thing here I can see a few potential problems so it could do with an overhaul, but it would be nice to just get the immediate bugs fixed first. |
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.
Look good! 😄
Sorry for being picky it's always traumatic especially with first PRs. Great work on finding this! 👍
Alright, but stand by. I'm putting in a few more if... is_valid() checks that should be in these files. |
BTW is the list of fixed issues in the OP still up-to-date with the current state of this PR? |
Ah yes this is correct the commit message needs to be properly filled out. See: |
Ok. I added more It should fix all of the Fixes I listed. The probablies and bugsquad add are unknown. |
…and possibly reused. Fixes godotengine#53374
I have moved the assignments inside the if statements. I have limited the commit message to only fixing my bug report. |
Thanks! |
Cherry-picked for 3.4.1. |
Thank you! |
Background
#53374 highlights an issue of disappearing meshes and error spam.
The root cause is when RIDs are freed, they leave a dangling pointer. Freed RIDs are not safe to free again, at least by the
VisualServer
orPhysicsServer
. Doing so may randomly free other mesh instances if the invalid pointer matches one already in use by another RID.Some areas in the engine, such as
SpatialEditor
continually spamVisualServer::free(RID)
with already freed RIDs, so though uncommon, freeing RIDs that other classes own occurs far too frequently.Changes
VisualServer
orPhysicsServer
in the engine, and possibly reused (i.e. not freed in the destructor) withrid = RID();
.Fixes #53374, #44642, #38229, #48433, #47356, #44712
Probably fixes: #41360, #50630