Fix T94713: Alembic crash with empty frames and velocities
Some software or processing tools (videogrammetry in this case) may export malformed files with velocity data even when the frame is empty for some reason. We need to explicity compare the data size with the vertex size, and refuse to load the attribute if there is a data size mismatch.
This commit is contained in:
@@ -463,13 +463,17 @@ static void read_velocity(const V3fArraySamplePtr &velocities,
|
||||
const CDStreamConfig &config,
|
||||
const float velocity_scale)
|
||||
{
|
||||
const int num_velocity_vectors = static_cast<int>(velocities->size());
|
||||
if (num_velocity_vectors != config.mesh->totvert) {
|
||||
/* Files containing videogrammetry data may be malformed and export velocity data on missing
|
||||
* frames (most likely by copying the last valid data). */
|
||||
return;
|
||||
}
|
||||
|
||||
CustomDataLayer *velocity_layer = BKE_id_attribute_new(
|
||||
&config.mesh->id, "velocity", CD_PROP_FLOAT3, ATTR_DOMAIN_POINT, nullptr);
|
||||
float(*velocity)[3] = (float(*)[3])velocity_layer->data;
|
||||
|
||||
const int num_velocity_vectors = static_cast<int>(velocities->size());
|
||||
BLI_assert(num_velocity_vectors == config.mesh->totvert);
|
||||
|
||||
for (int i = 0; i < num_velocity_vectors; i++) {
|
||||
const Imath::V3f &vel_in = (*velocities)[i];
|
||||
copy_zup_from_yup(velocity[i], vel_in.getValue());
|
||||
|
Reference in New Issue
Block a user