Merge pull request #80377 from YuriSizov/importers-are-made-to-be-alone

Register and cleanup resource importer singletons in a predictable way
This commit is contained in:
Rémi Verschelde 2023-08-09 17:46:33 +02:00
commit 1b132b7c23
No known key found for this signature in database
GPG Key ID: C3336907360768E1
7 changed files with 39 additions and 20 deletions

View File

@ -6928,8 +6928,7 @@ EditorNode::EditorNode() {
{
// Register importers at the beginning, so dialogs are created with the right extensions.
Ref<ResourceImporterTexture> import_texture;
import_texture.instantiate();
Ref<ResourceImporterTexture> import_texture = memnew(ResourceImporterTexture(true));
ResourceFormatImporter::get_singleton()->add_importer(import_texture);
Ref<ResourceImporterLayeredTexture> import_cubemap;
@ -6947,8 +6946,7 @@ EditorNode::EditorNode() {
import_cubemap_array->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP_ARRAY);
ResourceFormatImporter::get_singleton()->add_importer(import_cubemap_array);
Ref<ResourceImporterLayeredTexture> import_3d;
import_3d.instantiate();
Ref<ResourceImporterLayeredTexture> import_3d = memnew(ResourceImporterLayeredTexture(true));
import_3d->set_mode(ResourceImporterLayeredTexture::MODE_3D);
ResourceFormatImporter::get_singleton()->add_importer(import_3d);
@ -6988,12 +6986,10 @@ EditorNode::EditorNode() {
import_shader_file.instantiate();
ResourceFormatImporter::get_singleton()->add_importer(import_shader_file);
Ref<ResourceImporterScene> import_scene;
import_scene.instantiate();
Ref<ResourceImporterScene> import_scene = memnew(ResourceImporterScene(false, true));
ResourceFormatImporter::get_singleton()->add_importer(import_scene);
Ref<ResourceImporterScene> import_animation;
import_animation = Ref<ResourceImporterScene>(memnew(ResourceImporterScene(true)));
Ref<ResourceImporterScene> import_animation = memnew(ResourceImporterScene(true, true));
ResourceFormatImporter::get_singleton()->add_importer(import_animation);
{

View File

@ -474,12 +474,19 @@ bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_p
ResourceImporterLayeredTexture *ResourceImporterLayeredTexture::singleton = nullptr;
ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() {
singleton = this;
ResourceImporterLayeredTexture::ResourceImporterLayeredTexture(bool p_singleton) {
// This should only be set through the EditorNode.
if (p_singleton) {
singleton = this;
}
mode = MODE_CUBEMAP;
}
ResourceImporterLayeredTexture::~ResourceImporterLayeredTexture() {
if (singleton == this) {
singleton = nullptr;
}
}
void ResourceImporterLayeredTexture::_check_compress_ctex(const String &p_source_file, Ref<LayeredTextureImport> r_texture_import) {

View File

@ -119,7 +119,7 @@ public:
void set_mode(Mode p_mode) { mode = p_mode; }
ResourceImporterLayeredTexture();
ResourceImporterLayeredTexture(bool p_singleton = false);
~ResourceImporterLayeredTexture();
};

View File

@ -2607,15 +2607,28 @@ void ResourceImporterScene::ResourceImporterScene::show_advanced_options(const S
SceneImportSettings::get_singleton()->open_settings(p_path, animation_importer);
}
ResourceImporterScene::ResourceImporterScene(bool p_animation_import) {
if (p_animation_import) {
animation_singleton = this;
} else {
scene_singleton = this;
ResourceImporterScene::ResourceImporterScene(bool p_animation_import, bool p_singleton) {
// This should only be set through the EditorNode.
if (p_singleton) {
if (p_animation_import) {
animation_singleton = this;
} else {
scene_singleton = this;
}
}
animation_importer = p_animation_import;
}
ResourceImporterScene::~ResourceImporterScene() {
if (animation_singleton == this) {
animation_singleton = nullptr;
}
if (scene_singleton == this) {
scene_singleton = nullptr;
}
}
void ResourceImporterScene::add_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority) {
ERR_FAIL_COND(p_importer.is_null());
if (p_first_priority) {

View File

@ -296,7 +296,8 @@ public:
virtual bool can_import_threaded() const override { return false; }
ResourceImporterScene(bool p_animation_import = false);
ResourceImporterScene(bool p_animation_import = false, bool p_singleton = false);
~ResourceImporterScene();
template <class M>
static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale);

View File

@ -789,10 +789,12 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co
ResourceImporterTexture *ResourceImporterTexture::singleton = nullptr;
ResourceImporterTexture::ResourceImporterTexture() {
if (!singleton) {
ResourceImporterTexture::ResourceImporterTexture(bool p_singleton) {
// This should only be set through the EditorNode.
if (p_singleton) {
singleton = this;
}
CompressedTexture2D::request_3d_callback = _texture_reimport_3d;
CompressedTexture2D::request_roughness_callback = _texture_reimport_roughness;
CompressedTexture2D::request_normal_callback = _texture_reimport_normal;

View File

@ -107,7 +107,7 @@ public:
virtual bool are_import_settings_valid(const String &p_path) const override;
virtual String get_import_settings_string() const override;
ResourceImporterTexture();
ResourceImporterTexture(bool p_singleton = false);
~ResourceImporterTexture();
};