Commit: 7351253064d96f12df07a477108f416d581a970d
Author: Kévin Dietrich
Date:   Tue Jul 12 11:44:33 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB7351253064d96f12df07a477108f416d581a970d

Prevent misusage of object path property, display an error in the
modifier UI if necessary.

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

M       source/blender/alembic/ABC_alembic.h
M       source/blender/alembic/intern/alembic_capi.cc
M       source/blender/modifiers/intern/MOD_meshsequencecache.c

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

diff --git a/source/blender/alembic/ABC_alembic.h 
b/source/blender/alembic/ABC_alembic.h
index f1ba6c3..940793f 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -89,7 +89,8 @@ struct DerivedMesh *ABC_read_mesh(AbcArchiveHandle *handle,
                                   struct Object *ob,
                                   struct DerivedMesh *dm,
                                   const char *object_path,
-                                  const float time);
+                                  const float time,
+                                  const char **err_str);
 
 bool ABC_has_velocity_cache(AbcArchiveHandle *handle, const char *object_path, 
const float time);
 void ABC_get_velocity_cache(AbcArchiveHandle *handle, const char *object_path, 
float *values, float time);
diff --git a/source/blender/alembic/intern/alembic_capi.cc 
b/source/blender/alembic/intern/alembic_capi.cc
index 97d9c18..f4d956e 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -981,33 +981,56 @@ static DerivedMesh *read_curves_sample(Object *ob, const 
IObject &iobject, const
        return CDDM_from_curve(ob);
 }
 
-DerivedMesh *ABC_read_mesh(AbcArchiveHandle *handle, Object *ob, DerivedMesh 
*dm, const char *object_path, const float time)
+DerivedMesh *ABC_read_mesh(AbcArchiveHandle *handle,
+                           Object *ob,
+                           DerivedMesh *dm,
+                           const char *object_path,
+                           const float time,
+                           const char **err_str)
 {
        IArchive *archive = archive_from_handle(handle);
 
        if (!archive || !archive->valid()) {
-               return dm;
+               *err_str = "Invalid archive!";
+               return NULL;
        }
 
        IObject iobject;
        find_iobject(archive->getTop(), iobject, object_path);
 
        if (!iobject.valid()) {
+               *err_str = "Invalid object: verify object path";
                return NULL;
        }
 
        const ObjectHeader &header = iobject.getHeader();
 
        if (IPolyMesh::matches(header)) {
+               if (ob->type != OB_MESH) {
+                       *err_str = "Object type mismatch: object path points to 
a mesh!";
+                       return NULL;
+               }
+
                return read_mesh_sample(dm, iobject, time);
        }
        else if (IPoints::matches(header)) {
+               if (ob->type != OB_MESH) {
+                       *err_str = "Object type mismatch: object path points to 
a point cloud (requires a mesh object)!";
+                       return NULL;
+               }
+
                return read_points_sample(dm, iobject, time);
        }
        else if (ICurves::matches(header)) {
+               if (ob->type != OB_CURVE) {
+                       *err_str = "Object type mismatch: object path points to 
a curve!";
+                       return NULL;
+               }
+
                return read_curves_sample(ob, iobject, time);
        }
 
+       *err_str = "Unsupported object type: verify object path"; // or poke 
developer
        return NULL;
 }
 
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c 
b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index d44ccff..d088ce0 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -93,11 +93,18 @@ static DerivedMesh *applyModifier(ModifierData *md, Object 
*ob,
        const float frame = BKE_scene_frame_get(scene);
        const float time = BKE_cachefile_time_offset(mcmd->cache_file, frame, 
FPS);
 
+       const char *err_str = NULL;
+
        DerivedMesh *result = ABC_read_mesh(mcmd->cache_file->handle,
                                            ob,
                                            dm,
                                            mcmd->abc_object_path,
-                                           time);
+                                           time,
+                                           &err_str);
+
+       if (err_str) {
+               modifier_setError(md, "%s", err_str);
+       }
 
        return result ? result : dm;
        UNUSED_VARS(flag);

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

Reply via email to