Segmentation fault while acessing ArraySamplePtr

97 views
Skip to first unread message

Hans Baldzuhn

unread,
Mar 20, 2018, 5:13:23 AM3/20/18
to alembic-discussion
Hi every one !

I'm currently working on a support for particle read and write inside maya. I'm working on the final step with testing on real production data.
I will send a push request when everything is stable.

Reading default IPointSchema data works without issue. But my implementation tries to get all possible geomparam as well.
My production alembic file comes from houdini. It is a foam simulation with at most 73846 particles.

Reading positionm velocity and width works fine, but the IPointSchema also has two arbGeomParam, "life" and "age" (custom particle attributes)

when the reader reach a sample with lots of particles (it is not consistent), I get a Segmentation Fault

Here is my code:



// Array property comes from somewhere else in the code
 
Alembic::Abc::IArrayProperty arrayProp;

 
Alembic::AbcCoreAbstract::ArraySamplePtr samp;

 arrayProp
.get(samp, Alembic::Abc::ISampleSelector(index));
 
unsigned int sampSize = (unsigned int)samp->size();

MDoubleArray doubleArray;
doubleArray.setLength(sampSize);

 
double * vals = (double *) samp->getData();

// Looping here on purpose to check when it's failing
 
for (unsigned int i = 0; i < sampSize; ++i)
 
{
     doubleArray
[i] = vals[i];
 
}


At that particular moment, sampSize == 16972
the segmentation fault hits when reaching element 9493

I tried feeding the MDoubleArray with contant value to make sure the error doesn't comes from the maya object and it works fine.

What could be my mistake here ? if the data returned by the alembic sample is not the size returned by getSize(), what could I do ?

Best,
Hans


Lucas Miller

unread,
Mar 20, 2018, 1:37:55 PM3/20/18
to alembic-d...@googlegroups.com
Are you sure your arrayProp is a double and not a float?

arrayProp.getDataType()

https://github.com/alembic/alembic/blob/master/lib/Alembic/AbcCoreAbstract/DataType.h

Lucas
> --
> You received this message because you are subscribed to the Google Groups
> "alembic-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to alembic-discuss...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Hans Baldzuhn

unread,
Mar 20, 2018, 1:47:09 PM3/20/18
to alembic-d...@googlegroups.com
I need to use a double at the end, I can't avoid the conversion. Maya Nparticle per particle attribute can only be of two types : double and vector (double vector).

I assumed there would be no harm to cast a float (and anything by the way) to a double.

would:
double * vals = (double *) samp->getData();

and:
float* vals = (float *) samp->getData();

return two different array size ?


> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "alembic-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/alembic-discussion/r1wU-gUlD3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to alembic-discussion+unsub...@googlegroups.com.

Hans Baldzuhn

unread,
Mar 20, 2018, 2:11:22 PM3/20/18
to alembic-d...@googlegroups.com
Ok, forget my question !

I am doing to much python ...

I assumed that casting the result of getData() to a pointer of doubles would be the same as casting to the correct data and then casting each element as double.

And now understand why the data is all crap ...

Thanks ! I guess the gigantic swich code has to get back in my code !

Hans


Lucas Miller

unread,
Mar 20, 2018, 2:14:34 PM3/20/18
to alembic-d...@googlegroups.com
For posterity:

If the data was originally a float then the overall number of bytes in
the buffer will be half as big as the double.

You can either cast the data to the float and copy the values over, or
call IArrayProperty::getDimensions to figure out the number of
elements in your array, allocate it's buffer, and then use
IArrayProperty::getAs to read it AS a double array.

Lucas
> --
> You received this message because you are subscribed to the Google Groups
> "alembic-discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to alembic-discuss...@googlegroups.com.

Hans Baldzuhn

unread,
Mar 20, 2018, 5:12:44 PM3/20/18
to alembic-discussion
That's way better !

Thank you very much, it works like a charm.
I don't even need to worries about the POD now. When accessing the arrayProperty, it has already passed a compatibility test with maya particle data and I know it is a numeric property. The extent is carried over as well so I just pay attention to allocate correctly.

Hans
Reply all
Reply to author
Forward
0 new messages