Fix editor freezing and eventually crashing when importing resources per drag & drop #55373
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 #53871
When scanning for new and modified resource files, the
EditorFileSystem
class creates duplicate item actions when assets are imported via drag & drop. This causes the import process to fail with an error dialog that freezes the engine. Closing the dialog finally crashes the editor. This PR prevents duplicate file actions to be created.Might also fix #55087, but more information from OP is necessary to be sure.
Details
The
EditorFileSystem
class checks the file system for changes due to importing, modifying and deleting resources. This is done on multiple threads that fill thescan_actions
list with actions to perform on the affected files. It gets processed inEditorFileSystem::_update_scan_actions
. After all actions have been processed, the list is reset at the end of that function.The problem arises because the function can get called again before it reaches the part that clears
scan_actions
, leaving all the actions that have already been processed inscan_actions
, adding new actions on top, and running the function again. This will perform the actions from the previous run again along with the new ones. This causes numerous problems, the most visible ones are the reported issue and the fact that newly imported resources appear to have been imported twice. This is also mentioned in the issue above.The PR does two things:
EditorFileSystem::_update_scan_actions
handles the processing ofscan_actions
like a FIFO queue and removes a scanned action from the list as soon as it is done with it. This way, no action will be proccessed twice even if there are new actions added to the end of the queue before the function is done running.