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

Register and cleanup resource importer singletons in a predictable way #80377

Merged

Conversation

YuriSizov
Copy link
Contributor

@YuriSizov YuriSizov commented Aug 7, 2023

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 (ClassDB::is_parent_class(name, "ResourceImporter") && name != "EditorImportPlugin" && ClassDB::can_instantiate(name)) {
	import_option = true;
	ResourceImporter *resimp = Object::cast_to<ResourceImporter>(ClassDB::instantiate(name));
	List<ResourceImporter::ImportOption> options;
	resimp->get_import_options("", &options);
	for (int i = 0; i < options.size(); i++) {
		const PropertyInfo &prop = options[i].option;
		properties.push_back(prop);
		import_options_default[prop.name] = options[i].default_value;
	}
	own_properties = properties;
	memdelete(resimp);
}

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).

editor/editor_node.cpp Outdated Show resolved Hide resolved
@YuriSizov YuriSizov force-pushed the importers-are-made-to-be-alone branch from 034c817 to 237515d Compare August 7, 2023 15:49
@YuriSizov YuriSizov added the crash label Aug 9, 2023
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.

Seems like a good option to solve this.

Would like a check from @RandomShaper but he's currently on holiday, so he can review post merge.

@akien-mga akien-mga merged commit 1b132b7 into godotengine:master Aug 9, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

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.

Random crash when trying to open a scene
2 participants