-
-
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
Reentrency crash when calling EditorFileSystem::scan() while import in progress. #54864
Comments
Ensure no publicly callable functions can trigger `_notification` during a call to `EditorFileSystem::_notification`. Fixes godotengine#54864 This change guards all functions which can set `set_process(true)`, and invokes them at the end of the currently-running `NOTIFICATION_PROCESS`.
Ensure no publicly callable functions can trigger `_notification` during a call to `EditorFileSystem::_notification`. Fixes godotengine#54864 This change guards all functions which can set `set_process(true)`, and invokes them at the end of the currently-running `NOTIFICATION_PROCESS`.
@lyuma Did we work around it? How important is this to be solved? |
Had to update the test project for FileAccess. The problem still happens. @fire In my project, we worked around it using the I think this crash doesn't currently happen in normal editor use because the operating system trigger for window focus and scanning acts as a sort of synchronization point, and it doesn't process operating system events within a reentrant main loop. See also: PR #54918 which is addressing some part of this issue, but I'm not sure if it's a complete fix. |
#73214 sounds related, could you see if it solved (or more likely worked around) this issue? |
I was able to reproduce the crash in RC1, but not in RC2 or in my own build (with #73214 applied). So the crash is fixed. To reproduce, I had to make a couple fixes to MRP. Edited async_importer.gd line 47:
I also had to change the So I think the original issue got fixed somehow and can no longer be reproduced. That said, the files are failing to generate ".import" files and hence failing to import properly, so it's debatable whether or not this is a fix, but they do import successfully if the editor later loses and regains focus. It's certainly better than crashing. Okay I found that calling EditorFileSystem,update_file(f) after creating that file seemed to make the MRP import all files successfully in RC2. There seems to be some nuance in this part of the code:
Even though the .import file was already created and update_file was called once already, #73214 may cause these to be ignored in some cases if there is already an import in progress. Putting the scan() after the update_file seems to make it work a bit more often but now it randomly gets stuck on some file or other. In the cases it gets stuck, not calling scan() seems to get it unstuck, but there's no way to know if the race was hit, so I ended up diong:
and oddly enough with this code, it seems to import successfully every time. My theory is the randomness gives it a way out of the reentrant main loop. Anyway clearly this is a pathological case. I've since found that calling |
Godot version
4.0.dev 7211012
System information
Windows 10, Vulkan
Issue description
While Godot is importing files, it may call the Main::iteration() any number of times. This will trigger GDScript code to execute. If this GDScript code adds any files into the project and calls
EditorFilesystem::scan()
during this time, there is a chance that Godot will crash.I know someone's going to tell me well if it crashes, don't do that. But the point of this issue is it's never safe to call EditorFileSystem::scan in its current state, since there's some chance it is currently inside a nested
Main::iteration
call.However, from what I can tell so far, there is no way for GDScript to know if this
Main::iteration()
call is reentrant or not. Waiting for the next frame isn't good enough. Waiting 1 second also isn't good enough, since the current import could take longer than that.The following change works around the issue, but also prevents the ProgressDialog from showing up during all imports. Ideally there would be a better solution.
Steps to reproduce
_temp0.png
or_temp0_retry.png
then click out and back into the window once or twice.Commenting out the calls to
scan()
avoids the crash, but require that the user alt-tab in and out of the editor repeatedly to complete the test.Minimal reproduction project
Updated for 4.0 beta2 (FileAccess change) import_reentrancy4b2.zip
import_reentrancy4.zipThe text was updated successfully, but these errors were encountered: