Discussion:
[ITK-users] Segmentation fault in itkBinaryMask3DMeshSource
Francois Budin
2017-08-11 14:44:46 UTC
Permalink
Hello Mihail,

Thank you for the bug report. I found that there was a limitation in the
current implementation due to the fact that it uses "unsigned short"
variables. I will submit a patch and share it with you for your review. It
should correct your problem. Is it ok to add your data you shared in this
email to the ITK tests?

Thanks,
Francois

On Thu, Aug 10, 2017 at 6:50 PM, Mihail Isakov via Insight-users <
Hello,
i wonder how i could avoid crash in itkBinaryMask3DMeshSource (actual
version). In most cases the filter works excellent, but some files
bring it to segmentation fault.
Segmentation fault
Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx
2343 if ( currentframetmp[i][0] != 0 )
2344 {
2345 m_CurrentFrame[m_CurrentFrameIndex][1] =
currentframetmp[i][1]; <-------------
2346 m_CurrentFrame[m_CurrentFrameIndex++][0] =
currentframetmp[i][0];
the value of 'm_CurrentFrameIndex' in debugger is 65000, 'i' is 1
Minimal project with test file is here
https://drive.google.com/file/d/0ByBLJ2-U1t9xUm51d2Mtdzg1ZjQ/view?usp=
sharing
Thanks.
Regards,
Mihail
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Francois Budin
2017-08-14 13:00:55 UTC
Permalink
Thank you for checking if we could use the data to add tests. I will try to
generate an image that is large enough to create the same problem.
Replacing the unsigned short with ints is very similar to what I have done
on my local branch (I used long), so I am glad to see that this solution
also works for you.
I'll look into the allocations in the constructor to see if things can be
improved. This might be for a second patch.

Best,
François

On Mon, Aug 14, 2017 at 1:53 AM, Mihail Isakov via Insight-users <
On Fri, Aug 11, 2017 at 4:44 PM, Francois Budin
Post by Francois Budin
I found that there was a limitation in the
current implementation due to the fact that it uses "unsigned short"
variables.
Thank you very much. Fantastic! I changed in itkBinaryMask3DMeshSource.h
unsigned short m_CurrentRowIndex;
unsigned short m_CurrentFrameIndex;
unsigned short m_LastRowNum;
unsigned short m_LastFrameNum;
unsigned short m_CurrentRowNum;
unsigned short m_CurrentFrameNum;
to 'int' and it works, no crashes.
BTW, IMHO, it looks like variables m_NodeLimit(2000) and int
m_CellLimit(4000)
and allocations in constructor
this->GetOutput()->GetPoints()->Reserve(m_NodeLimit);
this->GetOutput()->GetCells()->Reserve(m_CellLimit);
don't have any effect and can be deleted... I generated huge meshes
without problems
very fast (with or without those limits and allocations).
Also i have seen that 3D binary images with dimension 1 cause
segmentation fault of filter too,
eg. this one
https://drive.google.com/file/d/0ByBLJ2-U1t9xS2VCa0RnVVdBYjg/view?usp=
sharing
It not relevant to unsigned short issue above.
Of course such images should not be used at all to generate mesh,
the same for the first noisy image, but anyway for filter robustness
some precondition check might be
done. The filter is very good, very fast.
Post by Francois Budin
Is it ok to add your data you shared in this
I am sorry, i asked the owner of the original data set i derived the
image from. Unfortunately he don't want to add it permanently to tests
due to some kind of policy. Sorry
Regards,
Mihail
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Loading...