[Bf-blender-cvs] [4ab735a46ed] soc-2019-fast-io: [Fast import/export] Fixed two off by one bugs and writing UVs indexes even though none are available

Hugo Sales noreply at git.blender.org
Fri Jun 28 18:45:15 CEST 2019


Commit: 4ab735a46ed475be19d531346a68aa243b2e3699
Author: Hugo Sales
Date:   Fri Jun 28 17:45:08 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB4ab735a46ed475be19d531346a68aa243b2e3699

[Fast import/export] Fixed two off by one bugs and writing UVs indexes even though none are available

===================================================================

M	source/blender/editors/io/intern/iterators.hpp
M	source/blender/editors/io/intern/obj.cpp

===================================================================

diff --git a/source/blender/editors/io/intern/iterators.hpp b/source/blender/editors/io/intern/iterators.hpp
index e934a24ef06..60379dbd438 100644
--- a/source/blender/editors/io/intern/iterators.hpp
+++ b/source/blender/editors/io/intern/iterators.hpp
@@ -559,7 +559,9 @@ struct deduplicated_iterator {
       : deduplicated_iterator(mesh, dp, total, SourceIter{mesh})
   {
     // Reserve space so we don't constantly allocate
+    // if (dedup_pair.second.size() + reserve > dedup_pair.second.capacity()) {
     dedup_pair.second.reserve(reserve);
+    // }
     // Need to insert the first element, because we need to dereference before incrementing
     if (this->it != this->it.end()) {
       auto p = dedup_pair.first.insert(std::make_pair(*this->it, total++));
@@ -578,7 +580,7 @@ struct deduplicated_iterator {
   deduplicated_iterator &operator++()
   {
     // Handle everything until the next different element, or the end, by...
-    while (true) {
+    while (this->it != this->it.end()) {
       // going to the next element of the `SourceIter`
       ++this->it;
       // if at the end, we're done
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index bbad8ebb413..702ae602b82 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -305,24 +305,24 @@ bool OBJ_export_mesh(bContext *UNUSED(C),
     // Loop index
     int li = p.loopstart;
     for (const MLoop &l : common::loop_of_poly_iter(mesh, p)) {
-      ulong vx = vertex_total + l.v;
-      ulong uv = 0;
-      ulong no = 0;
-      if (settings->export_uvs) {
+      ulong vx = vertex_total + l.v + 1;
+      ulong uv = 1;
+      ulong no = 1;
+      if (settings->export_uvs && mesh->mloopuv != nullptr) {
         if (format_specific->dedup_uvs)
-          uv = uv_mapping[uv_initial_count + li]->second;
+          uv = uv_mapping[uv_initial_count + li]->second + 1;
         else
-          uv = uv_initial_count + li;
+          uv = uv_initial_count + li + 1;
       }
       if (settings->export_normals) {
         if (format_specific->dedup_normals)
-          no = no_mapping[no_initial_count + l.v]->second;
+          no = no_mapping[no_initial_count + l.v]->second + 1;
         else
-          no = no_initial_count + l.v;
+          no = no_initial_count + l.v + 1;
       }
-      if (settings->export_uvs && settings->export_normals)
+      if (settings->export_uvs && settings->export_normals && mesh->mloopuv != nullptr)
         fprintf(file, " %lu/%lu/%lu", vx, uv, no);
-      else if (settings->export_uvs)
+      else if (settings->export_uvs && mesh->mloopuv != nullptr)
         fprintf(file, " %lu/%lu", vx, uv);
       else if (settings->export_normals)
         fprintf(file, " %lu//%lu", vx, no);
@@ -452,6 +452,7 @@ void OBJ_export_start(bContext *C, ExportSettings *const settings)
         std::cerr << "Couldn't export materials\n";
       }
     }
+    fclose(obj_file);
   }
 }



More information about the Bf-blender-cvs mailing list