[Bf-blender-cvs] [201d0d0ec26] temp-alembic-exporter-T73363-ms2: Fix crash when exporting

Sybren A. Stüvel noreply at git.blender.org
Mon Mar 23 17:24:05 CET 2020


Commit: 201d0d0ec26ce67250e2f74280121ea23b75f335
Author: Sybren A. Stüvel
Date:   Mon Mar 23 17:14:59 2020 +0100
Branches: temp-alembic-exporter-T73363-ms2
https://developer.blender.org/rB201d0d0ec26ce67250e2f74280121ea23b75f335

Fix crash when exporting

The OAlembic object was copied, and my assumption that this would work fine
was wrong.

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

M	source/blender/io/alembic/intern/export/abc_archive.cc
M	source/blender/io/alembic/intern/export/abc_archive.h
M	source/blender/io/alembic/intern/export/abc_export_capi.cc
M	source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
M	source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
M	source/blender/io/alembic/intern/export/abc_writer_abstract.cc
M	source/blender/io/alembic/intern/export/abc_writer_transform.cc

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

diff --git a/source/blender/io/alembic/intern/export/abc_archive.cc b/source/blender/io/alembic/intern/export/abc_archive.cc
index 1bc75a29ba7..ed46030f9ce 100644
--- a/source/blender/io/alembic/intern/export/abc_archive.cc
+++ b/source/blender/io/alembic/intern/export/abc_archive.cc
@@ -75,11 +75,10 @@ static MetaData create_abc_metadata(const Main *bmain, double scene_fps)
   return abc_metadata;
 }
 
-/* OArchive is just a wrapper for a pointer, so it can be copied. */
-static OArchive create_archive(std::ofstream *abc_ostream,
-                               const std::string &filename,
-                               MetaData &abc_metadata,
-                               bool write_ogawa)
+static OArchive *create_archive(std::ofstream *abc_ostream,
+                                const std::string &filename,
+                                MetaData &abc_metadata,
+                                bool write_ogawa)
 {
   /* Use stream to support unicode character paths on Windows. */
   if (write_ogawa) {
@@ -105,7 +104,7 @@ static OArchive create_archive(std::ofstream *abc_ostream,
 #endif
 
   Alembic::AbcCoreOgawa::WriteArchive archive_writer;
-  return OArchive(archive_writer(abc_ostream, abc_metadata), kWrapExisting, policy);
+  return new OArchive(archive_writer(abc_ostream, abc_metadata), kWrapExisting, policy);
 }
 
 /* Construct list of shutter samples.
@@ -177,6 +176,7 @@ ABCArchive::ABCArchive(const Main *bmain,
                        const Scene *scene,
                        AlembicExportParams params,
                        std::string filename)
+    : archive(nullptr)
 {
   double scene_fps = FPS;
   MetaData abc_metadata = create_abc_metadata(bmain, scene_fps);
@@ -190,7 +190,7 @@ ABCArchive::ABCArchive(const Main *bmain,
   TimeSamplingPtr ts_shapes;
 
   ts_xform = create_time_sampling(scene_fps, params, params.frame_samples_xform);
-  time_sampling_index_transforms_ = archive.addTimeSampling(*ts_xform);
+  time_sampling_index_transforms_ = archive->addTimeSampling(*ts_xform);
 
   const bool export_animation = params.frame_start != params.frame_end;
   if (!export_animation || params.frame_samples_shape == params.frame_samples_xform) {
@@ -199,7 +199,7 @@ ABCArchive::ABCArchive(const Main *bmain,
   }
   else {
     ts_shapes = create_time_sampling(scene_fps, params, params.frame_samples_shape);
-    time_sampling_index_shapes_ = archive.addTimeSampling(*ts_shapes);
+    time_sampling_index_shapes_ = archive->addTimeSampling(*ts_shapes);
   }
 
   // Construct the frames to export.
@@ -213,6 +213,7 @@ ABCArchive::ABCArchive(const Main *bmain,
 
 ABCArchive::~ABCArchive()
 {
+  delete archive;
 }
 
 uint32_t ABCArchive::time_sampling_index_transforms() const
diff --git a/source/blender/io/alembic/intern/export/abc_archive.h b/source/blender/io/alembic/intern/export/abc_archive.h
index b074b9708a3..707943553f6 100644
--- a/source/blender/io/alembic/intern/export/abc_archive.h
+++ b/source/blender/io/alembic/intern/export/abc_archive.h
@@ -47,7 +47,7 @@ class ABCArchive {
   typedef std::set<double> Frames;
 
  public:
-  Alembic::Abc::OArchive archive;
+  Alembic::Abc::OArchive *archive;
 
   ABCArchive(const Main *bmain,
              const Scene *scene,
diff --git a/source/blender/io/alembic/intern/export/abc_export_capi.cc b/source/blender/io/alembic/intern/export/abc_export_capi.cc
index 9025f7b3ff6..0fc4879e165 100644
--- a/source/blender/io/alembic/intern/export/abc_export_capi.cc
+++ b/source/blender/io/alembic/intern/export/abc_export_capi.cc
@@ -95,7 +95,7 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo
   // OBox3dProperty archive_bounds_prop = Alembic::AbcGeom::CreateOArchiveBounds(
   //     m_writer->archive(), m_trans_sampling_index);
 
-  ABCHierarchyIterator iter(data->depsgraph, abc_archive, data->params);
+  ABCHierarchyIterator iter(data->depsgraph, &abc_archive, data->params);
 
   if (export_animation) {
     // Writing the animated frames is not 100% of the work, but it's our best guess.
diff --git a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
index c7f2bb30ab3..3117a89e7f9 100644
--- a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
@@ -43,7 +43,7 @@ extern "C" {
 namespace ABC {
 
 ABCHierarchyIterator::ABCHierarchyIterator(Depsgraph *depsgraph,
-                                           ABCArchive &abc_archive,
+                                           ABCArchive *abc_archive,
                                            const AlembicExportParams &params)
     : AbstractHierarchyIterator(depsgraph), abc_archive_(abc_archive), params_(params)
 {
diff --git a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
index cf455452e08..537958cb9e9 100644
--- a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.h
@@ -44,7 +44,7 @@ class ABCHierarchyIterator;
 
 struct ABCWriterConstructorArgs {
   Depsgraph *depsgraph;
-  ABCArchive &abc_archive;
+  ABCArchive *abc_archive;
   const std::string abc_path;
   const ABCHierarchyIterator *hierarchy_iterator;
   const AlembicExportParams &export_params;
@@ -52,12 +52,12 @@ struct ABCWriterConstructorArgs {
 
 class ABCHierarchyIterator : public AbstractHierarchyIterator {
  private:
-  ABCArchive &abc_archive_;
+  ABCArchive *abc_archive_;
   const AlembicExportParams &params_;
 
  public:
   ABCHierarchyIterator(Depsgraph *depsgraph,
-                       ABCArchive &abc_archive_,
+                       ABCArchive *abc_archive_,
                        const AlembicExportParams &params);
 
   virtual std::string make_valid_name(const std::string &name) const override;
diff --git a/source/blender/io/alembic/intern/export/abc_writer_abstract.cc b/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
index 2c48c1d3a70..4e324c8b215 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
+++ b/source/blender/io/alembic/intern/export/abc_writer_abstract.cc
@@ -75,7 +75,7 @@ const OObject ABCAbstractWriter::get_alembic_parent(HierarchyContext &context) c
   if (!parent.valid()) {
     /* An invalid parent object means "no parent", which should be translated to Alembic's top
      * archive object. */
-    return args_.abc_archive.archive.getTop();
+    return args_.abc_archive->archive->getTop();
   }
 
   return parent;
diff --git a/source/blender/io/alembic/intern/export/abc_writer_transform.cc b/source/blender/io/alembic/intern/export/abc_writer_transform.cc
index ebe24c231a1..b253c99d1c8 100644
--- a/source/blender/io/alembic/intern/export/abc_writer_transform.cc
+++ b/source/blender/io/alembic/intern/export/abc_writer_transform.cc
@@ -49,7 +49,7 @@ void ABCTransformWriter::do_write(HierarchyContext &context)
   copy_m44_axis_swap(parent_relative_matrix, parent_relative_matrix, ABC_YUP_FROM_ZUP);
 
   if (!abc_xform_.valid()) {
-    uint32_t ts_index = args_.abc_archive.time_sampling_index_transforms();
+    uint32_t ts_index = args_.abc_archive->time_sampling_index_transforms();
     abc_xform_ = OXform(get_alembic_parent(context), context.export_name, ts_index);
     context.custom_data = this;
   }



More information about the Bf-blender-cvs mailing list