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

Fix crash when reimporting AtlasTextures #60888

Closed
wants to merge 3 commits into from

Conversation

EspeuteClement
Copy link
Contributor

@EspeuteClement EspeuteClement commented May 8, 2022

The crash was caused by the reimport_files function trying to reimport the same atlas file multiple times using multithreading, which caused deadlocks and hung the editor.
This fix prevents files from being added to the reimport_files array if they are already present inside of it.

Fixes #54817

Note : I have only tested this fix on a sample project. This could potentially break more complex projects, but I'm not enough familiar with the godot import system to tell if that is the case. Someone knowledgable with that system should review this before merging.

Additionaly, I don't know if files that are both as key in groups_to_reimport and in the reimport_files array should be reimported when handling the reimport_filesarray. I left it as is, but maybe these files end up being reimported twice.

@EspeuteClement EspeuteClement changed the title Fixing crash when reimporting AtlasTextures Fixi crash when reimporting AtlasTextures May 8, 2022
@EspeuteClement EspeuteClement changed the title Fixi crash when reimporting AtlasTextures Fix crash when reimporting AtlasTextures May 8, 2022
@Calinou Calinou added this to the 4.0 milestone May 8, 2022
@EspeuteClement
Copy link
Contributor Author

So after further testing, it seems that adding

	for (int i = 0; i < reimport_files.size(); i++) {
+		if (groups_to_reimport.has(reimport_files[i].path)) {
+			continue;
+		}

		if (use_threads && reimport_files[i].threaded) {

to the reimport_files file function is indeed correct, as it seems to fix some other issues like the icon of the atlas texture not correctly updating after adding new sprites to the atlas, but I don't know if that could have unforeseen side effects.

@EspeuteClement
Copy link
Contributor Author

After checking the code, files that are in groups are reimported at the end of the function, so there is no point in reimporting them when importing all the files. I've added the proposed changes in a new commit.

@EspeuteClement
Copy link
Contributor Author

I have added another fix for the importing of group files that avoid them being re-imported at each tick of the editor because they didn't have valid uids

@@ -2121,6 +2144,11 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {

int from = 0;
for (int i = 0; i < reimport_files.size(); i++) {
if (groups_to_reimport.has(reimport_files[i].path)) {
//skip reimporting files that are in groups, as they will be reimported anyways
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change:

// Skip reimporting files that are in groups, as they will be reimported anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I based this comment style to match the other ones in editor_file_system.cpp, but yes they don't match the comment style guide at https://docs.godotengine.org/en/stable/community/contributing/code_style_guidelines.html#comment-style-guide

uid = ResourceUID::get_singleton()->create_id();
}

f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); //store in readable format
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change:

f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); // Store in readable format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copy/pasted this line from somewhere else in the file that had the same comment, but I can update this one to match the comment style guide yes. I'll do that later today

The crash was caused by the reimport_files function trying to reimport the atlas file multiple times using multithreading, which caused deadlocks and hang the editor.
This fix prevents files from being added to the reimport_files array if they are already present inside of it.

Fixes godotengine#54817
Files that are groups of other files will be reimported anyways at the end of the function, so there is no point in re-importing them before they are processed
This fix the concerned files being reimported at each tick of the editor
@EspeuteClement
Copy link
Contributor Author

I updated the pr to the latest master commits, and added the suggested changes to comment styles

@Faless
Copy link
Collaborator

Faless commented Dec 5, 2022

Closing as superseded by #68324

@Faless Faless closed this Dec 5, 2022
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.

Godot 4: impossible to restart after creating a TextureAtlas from PNGs
6 participants