Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix bug in insertion of lightmap caches into unwrap_cache

madsbangh51152af3da1a
diff --git a/editor/import/3d/resource_importer_obj.cpp b/editor/import/3d/resource_importer_obj.cpp
index 7b767fe0409..48ae55fb1d9 100644
--- a/editor/import/3d/resource_importer_obj.cpp
+++ b/editor/import/3d/resource_importer_obj.cpp
@@ -539,24 +539,26 @@ static Error _parse_obj(const String &p_path, List<Ref<ImporterMesh>> &r_meshes,
mesh->lightmap_unwrap_cached(Transform3D(), p_generate_lightmap_uv2_texel_size, p_src_lightmap_cache, lightmap_cache);
if (!lightmap_cache.is_empty()) {
- if (r_lightmap_caches.is_empty()) {
- r_lightmap_caches.push_back(lightmap_cache);
- } else {
- // MD5 is stored at the beginning of the cache data.
- const String new_md5 = String::md5(lightmap_cache.ptr());
-
- for (int i = 0; i < r_lightmap_caches.size(); i++) {
- const String md5 = String::md5(r_lightmap_caches[i].ptr());
- if (new_md5 < md5) {
- r_lightmap_caches.insert(i, lightmap_cache);
- break;
- }
+ // MD5 is stored at the beginning of the cache data.
+ const String new_md5 = String::md5(lightmap_cache.ptr());
+
+ bool handled = false;
+ for (int i = 0; i < r_lightmap_caches.size(); i++) {
+ const String md5 = String::md5(r_lightmap_caches[i].ptr());
+ if (new_md5 < md5) {
+ r_lightmap_caches.insert(i, lightmap_cache);
+ handled = true;
+ break;
+ }
- if (new_md5 == md5) {
- break;
- }
+ if (new_md5 == md5) {
+ handled = true;
+ break;
}
}
+ if (!handled) {
+ r_lightmap_caches.push_back(lightmap_cache);
+ }
}
}
diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp
index d2647dfee3e..1850ddf14ea 100644
--- a/editor/import/3d/resource_importer_scene.cpp
+++ b/editor/import/3d/resource_importer_scene.cpp
@@ -2878,23 +2878,26 @@ Node *ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_
importer_mesh->lightmap_unwrap_cached(xf, p_lightmap_texel_size, p_src_lightmap_cache, lightmap_cache);
if (!lightmap_cache.is_empty()) {
- if (r_lightmap_caches.is_empty()) {
- r_lightmap_caches.push_back(lightmap_cache);
- } else {
- String new_md5 = String::md5(lightmap_cache.ptr()); // MD5 is stored at the beginning of the cache data
-
- for (int i = 0; i < r_lightmap_caches.size(); i++) {
- String md5 = String::md5(r_lightmap_caches[i].ptr());
- if (new_md5 < md5) {
- r_lightmap_caches.insert(i, lightmap_cache);
- break;
- }
+ // MD5 is stored at the beginning of the cache data
+ const String new_md5 = String::md5(lightmap_cache.ptr());
+
+ bool handled = false;
+ for (int i = 0; i < r_lightmap_caches.size(); i++) {
+ String md5 = String::md5(r_lightmap_caches[i].ptr());
+ if (new_md5 < md5) {
+ r_lightmap_caches.insert(i, lightmap_cache);
+ handled = true;
+ break;
+ }
- if (new_md5 == md5) {
- break;
- }
+ if (new_md5 == md5) {
+ handled = true;
+ break;
}
}
+ if (!handled) {
+ r_lightmap_caches.push_back(lightmap_cache);
+ }
}
}