Register and cleanup resource importer singletons in a predictable way #80377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #80255. Replaces #79981.
I think I have an idea of what's happening. We create all importers in
EditorNode
, and we assume those will act as singletons (for some of them which implement the pattern). However, there is a possibility for something else to steal the instance, and then be discarded. In this case it looks like the doc generator does that. It has this bit:If this code runs after the
EditorNode
constructor, it will assume the place of the singleton, and then it will immediately be destroyed, nulling the reference. My proposed solution to this is to add a flag for the constructor so we explicitly decide which instance is going to be added as the singleton instance. I implemented it for all 3 importers that have singletons. And also made sure we don't leak anything on exit for all of them.Note that the layered texture importer has the singleton, but it's unused as far as I can see.
Due to this being a race condition of sorts, it's hard to reproduce reliably, thus making it harder to validate the fix. But I think the logic is solid. When testing note that the doc generator only runs if you don't have a valid docs cache. So make sure to delete it (
editor_data/cache/editor_doc_cache.res
).