Skip to content
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

Abort threaded preview generators on exit #84716

Conversation

YuriSizov
Copy link
Contributor

See #84200 (comment).

Basically, after the reimport is done we start to generate previews. This is a non-blocking operation and it is out of our control (as in, we don't know how much work it needs to do or when it will be done).

As such, we can't really wait for it to finish, so our only hope is that it correctly aborts on exiting the editor. Which it doesn't. As far as I can tell, it should handle exiting correctly, but there are so many threads and mutexes and semaphores involved, everything and anything can go wrong.

I managed to identify a couple of problems, which this PR addresses. First, we avoid restarting the editor directly from the surface upgrade tool. This is likely needed, because this dialog can appear when we try to load a scene or a mesh resource, and if in turn we trigger the editor restart from it, this may bring us back to resource loaders. And possibly create a lock.

Another issue is that some preview generators are threaded in their own right, on top of the EditorResourcePreview being threaded. These have their own semaphores and checks and they await for the next rendered frame from the RenderingServer. Which never happens at this stage, no matter how many times we do the sync. So I added an explicit abort operation that unlocks the semaphore immediately. It's crudely done, but it seems to resolve the issues and I can at least import Kenney's starter project in Godot 4.2 as expected.


While investigating, I made a couple of clean up changes. I've removed an unimplemented preview generator, renamed some variables for clarity, fixed order mistakes, and flattened for readability EditorResourcePreview::_iterate (should lead to no logical changes). Make sure to compare changes without whitespaces.

@YuriSizov YuriSizov force-pushed the 3d-resource-previews-are-out-to-get-you branch from ef49902 to e90ea87 Compare November 10, 2023 14:31
@YuriSizov
Copy link
Contributor Author

YuriSizov commented Nov 10, 2023

Note about testing: make sure to delete your resource preview cache in the editor data folder between runs (editor_data\cache) to guarantee that you trigger the generator.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing with the GDQuest 4.0 new features showcase, and Kenney's Starter Kit 3D Platformer.

This seems to fix the deadlock I was experiencing on those projects.

Rough testing procedure:

  • Delete .godot and editor cache
  • Open in 4.1.3 to import everything
  • Open in 4.2-beta5, trigger upgrade, see deadlock
  • Exit, clean changes to git history
  • Repeat all steps with a build including this PR instead of 4.2-beta5

@akien-mga akien-mga merged commit 848f93f into godotengine:master Nov 10, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@YuriSizov YuriSizov deleted the 3d-resource-previews-are-out-to-get-you branch November 10, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants