Merge pull request #69810 from trollodel/scene_importer_material_crash_fix
Ensure that generated import IDs are unique
This commit is contained in:
commit
2aaa6f6728
|
@ -142,24 +142,23 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
|
||||||
String import_id;
|
String import_id;
|
||||||
bool has_import_id = false;
|
bool has_import_id = false;
|
||||||
|
|
||||||
bool created = false;
|
|
||||||
if (!material_set.has(p_material)) {
|
|
||||||
material_set.insert(p_material);
|
|
||||||
created = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_material->has_meta("import_id")) {
|
if (p_material->has_meta("import_id")) {
|
||||||
import_id = p_material->get_meta("import_id");
|
import_id = p_material->get_meta("import_id");
|
||||||
has_import_id = true;
|
has_import_id = true;
|
||||||
} else if (!p_material->get_name().is_empty()) {
|
} else if (!p_material->get_name().is_empty()) {
|
||||||
import_id = p_material->get_name();
|
import_id = p_material->get_name();
|
||||||
has_import_id = true;
|
has_import_id = true;
|
||||||
|
} else if (unnamed_material_name_map.has(p_material)) {
|
||||||
|
import_id = unnamed_material_name_map[p_material];
|
||||||
} else {
|
} else {
|
||||||
import_id = "@MATERIAL:" + itos(material_set.size() - 1);
|
import_id = "@MATERIAL:" + itos(material_map.size());
|
||||||
|
unnamed_material_name_map[p_material] = import_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool created = false;
|
||||||
if (!material_map.has(import_id)) {
|
if (!material_map.has(import_id)) {
|
||||||
MaterialData md;
|
MaterialData md;
|
||||||
|
created = true;
|
||||||
md.has_import_id = has_import_id;
|
md.has_import_id = has_import_id;
|
||||||
md.material = p_material;
|
md.material = p_material;
|
||||||
|
|
||||||
|
@ -169,6 +168,7 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialData &material_data = material_map[import_id];
|
MaterialData &material_data = material_map[import_id];
|
||||||
|
ERR_FAIL_COND(p_material != material_data.material);
|
||||||
|
|
||||||
Ref<Texture2D> icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons"));
|
Ref<Texture2D> icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons"));
|
||||||
|
|
||||||
|
@ -564,10 +564,10 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati
|
||||||
|
|
||||||
base_path = p_path;
|
base_path = p_path;
|
||||||
|
|
||||||
material_set.clear();
|
|
||||||
mesh_set.clear();
|
mesh_set.clear();
|
||||||
animation_map.clear();
|
animation_map.clear();
|
||||||
material_map.clear();
|
material_map.clear();
|
||||||
|
unnamed_material_name_map.clear();
|
||||||
mesh_map.clear();
|
mesh_map.clear();
|
||||||
node_map.clear();
|
node_map.clear();
|
||||||
defaults.clear();
|
defaults.clear();
|
||||||
|
|
|
@ -107,6 +107,7 @@ class SceneImportSettings : public ConfirmationDialog {
|
||||||
HashMap<StringName, Variant> settings;
|
HashMap<StringName, Variant> settings;
|
||||||
};
|
};
|
||||||
HashMap<String, MaterialData> material_map;
|
HashMap<String, MaterialData> material_map;
|
||||||
|
HashMap<Ref<Material>, String> unnamed_material_name_map;
|
||||||
|
|
||||||
struct MeshData {
|
struct MeshData {
|
||||||
bool has_import_id;
|
bool has_import_id;
|
||||||
|
@ -141,7 +142,6 @@ class SceneImportSettings : public ConfirmationDialog {
|
||||||
void _fill_scene(Node *p_node, TreeItem *p_parent_item);
|
void _fill_scene(Node *p_node, TreeItem *p_parent_item);
|
||||||
|
|
||||||
HashSet<Ref<Mesh>> mesh_set;
|
HashSet<Ref<Mesh>> mesh_set;
|
||||||
HashSet<Ref<Material>> material_set;
|
|
||||||
|
|
||||||
String selected_type;
|
String selected_type;
|
||||||
String selected_id;
|
String selected_id;
|
||||||
|
|
Loading…
Reference in New Issue