Commit: 3bd45d384bccda2ad5a4665476f79ce7d4d9ed44
Author: Lukas Tönne
Date:   Mon Mar 9 12:52:51 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB3bd45d384bccda2ad5a4665476f79ce7d4d9ed44

Fix for some archive checks to make sure we don't access invalid data.

This can happen if the archive file cannot be opened for some reason.

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

M       source/blender/pointcache/alembic/abc_cloth.cpp
M       source/blender/pointcache/alembic/abc_mesh.cpp
M       source/blender/pointcache/alembic/abc_particles.cpp
M       source/blender/pointcache/alembic/abc_reader.cpp
M       source/blender/pointcache/alembic/abc_writer.cpp

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

diff --git a/source/blender/pointcache/alembic/abc_cloth.cpp 
b/source/blender/pointcache/alembic/abc_cloth.cpp
index 1cd95d3..b00a3b5 100644
--- a/source/blender/pointcache/alembic/abc_cloth.cpp
+++ b/source/blender/pointcache/alembic/abc_cloth.cpp
@@ -146,7 +146,7 @@ void AbcClothReader::open_archive(ReaderArchive *archive)
        BLI_assert(dynamic_cast<AbcReaderArchive*>(archive));
        AbcReader::abc_archive(static_cast<AbcReaderArchive*>(archive));
        
-       if (abc_archive()->archive.valid()) {
+       if (abc_archive()->archive) {
                IObject root = abc_archive()->archive.getTop();
                if (root.valid() && root.getChild(m_name)) {
                        m_points = IPoints(root, m_name);
diff --git a/source/blender/pointcache/alembic/abc_mesh.cpp 
b/source/blender/pointcache/alembic/abc_mesh.cpp
index eb0ceac..b9bf123 100644
--- a/source/blender/pointcache/alembic/abc_mesh.cpp
+++ b/source/blender/pointcache/alembic/abc_mesh.cpp
@@ -326,7 +326,7 @@ void AbcDerivedMeshReader::open_archive(ReaderArchive 
*archive)
        BLI_assert(dynamic_cast<AbcReaderArchive*>(archive));
        AbcReader::abc_archive(static_cast<AbcReaderArchive*>(archive));
        
-       if (abc_archive()->archive.valid()) {
+       if (abc_archive()->archive) {
                IObject root = abc_archive()->archive.getTop();
                if (root.valid() && root.getChild(m_name)) {
                        m_mesh = IPolyMesh(root, m_name);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp 
b/source/blender/pointcache/alembic/abc_particles.cpp
index 060c2a6..5b5aae9 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -99,7 +99,7 @@ void AbcParticlesReader::open_archive(ReaderArchive *archive)
        BLI_assert(dynamic_cast<AbcReaderArchive*>(archive));
        AbcReader::abc_archive(static_cast<AbcReaderArchive*>(archive));
        
-       if (abc_archive()->archive.valid()) {
+       if (abc_archive()->archive) {
                IObject root = abc_archive()->archive.getTop();
                m_points = IPoints(root, m_name);
        }
@@ -183,6 +183,9 @@ void AbcParticlePathcacheWriter::open_archive(WriterArchive 
*archive)
        BLI_assert(dynamic_cast<AbcWriterArchive*>(archive));
        AbcWriter::abc_archive(static_cast<AbcWriterArchive*>(archive));
 
+       if (!abc_archive()->archive)
+               return;
+
        OObject root = abc_archive()->archive.getTop();
        /* XXX non-escaped string construction here ... */
        m_curves = OCurves(root, m_name + m_suffix, 
abc_archive()->frame_sampling_index());
@@ -388,7 +391,7 @@ void AbcParticlePathcacheReader::open_archive(ReaderArchive 
*archive)
        BLI_assert(dynamic_cast<AbcReaderArchive*>(archive));
        AbcReader::abc_archive(static_cast<AbcReaderArchive*>(archive));
        
-       if (abc_archive()->archive.valid()) {
+       if (abc_archive()->archive) {
                IObject root = abc_archive()->archive.getTop();
                if (root.valid()) {
                        /* XXX non-escaped string construction here ... */
diff --git a/source/blender/pointcache/alembic/abc_reader.cpp 
b/source/blender/pointcache/alembic/abc_reader.cpp
index 6195014..148d78e 100644
--- a/source/blender/pointcache/alembic/abc_reader.cpp
+++ b/source/blender/pointcache/alembic/abc_reader.cpp
@@ -49,7 +49,7 @@ AbcReaderArchive::~AbcReaderArchive()
 
 bool AbcReaderArchive::get_frame_range(int &start_frame, int &end_frame)
 {
-       if (archive.valid()) {
+       if (archive) {
                double start_time, end_time;
                GetArchiveStartAndEndTime(archive, start_time, end_time);
                start_frame = (int)time_to_frame(start_time);
@@ -64,7 +64,10 @@ bool AbcReaderArchive::get_frame_range(int &start_frame, int 
&end_frame)
 
 std::string AbcReaderArchive::get_info()
 {
-       return abc_archive_info(archive);
+       if (archive)
+               return abc_archive_info(archive);
+       else
+               return "";
 }
 
 ISampleSelector AbcReaderArchive::get_frame_sample_selector(float frame)
@@ -74,7 +77,7 @@ ISampleSelector 
AbcReaderArchive::get_frame_sample_selector(float frame)
 
 PTCReadSampleResult AbcReaderArchive::test_sample(float frame)
 {
-       if (archive.valid()) {
+       if (archive) {
                double start_time, end_time;
                GetArchiveStartAndEndTime(archive, start_time, end_time);
                float start_frame = time_to_frame(start_time);
diff --git a/source/blender/pointcache/alembic/abc_writer.cpp 
b/source/blender/pointcache/alembic/abc_writer.cpp
index 80632d3..9c66d60 100644
--- a/source/blender/pointcache/alembic/abc_writer.cpp
+++ b/source/blender/pointcache/alembic/abc_writer.cpp
@@ -52,9 +52,11 @@ AbcWriterArchive::AbcWriterArchive(Scene *scene, const 
std::string &filename, Er
 //     archive = OArchive(AbcCoreHDF5::WriteArchive(), filename, 
Abc::ErrorHandler::kThrowPolicy);
        archive = OArchive(AbcCoreOgawa::WriteArchive(), filename, 
Abc::ErrorHandler::kThrowPolicy);
        
-       chrono_t cycle_time = this->seconds_per_frame();
-       chrono_t start_time = this->start_time();
-       m_frame_sampling = archive.addTimeSampling(TimeSampling(cycle_time, 
start_time));
+       if (archive) {
+               chrono_t cycle_time = this->seconds_per_frame();
+               chrono_t start_time = this->start_time();
+               m_frame_sampling = 
archive.addTimeSampling(TimeSampling(cycle_time, start_time));
+       }
        
        PTC_SAFE_CALL_END_HANDLER(m_error_handler)
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to