Hi Christian,<div><br><div>We were affected too here, also with the CurvatureFlowImageFilter, Qt 4.7.4, ITK 3.20.1 and Mac OSX Lion.</div><div>So thanks a lot for solving this issue, its erratic behaviour was making it very difficult to catch !</div>
<div><br></div><div>-Simon</div><div><br></div><div><br><br><div class="gmail_quote">On Tue, Oct 18, 2011 at 22:31, Christian Lackas <span dir="ltr"><<a href="mailto:lackas@invicro.com">lackas@invicro.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">* Christian Lackas <<a href="mailto:lackas@invicro.com">lackas@invicro.com</a>> [111018 17:50]:<br>
<br>
Hi Everybody,<br>
<br>
thanks for all input. The ITK Object Factory was a dead end (there were<br>
no factories and then itkNewMacro falls back to a regular 'new').<br>
However, I finally found the issue and it is a tricky one, that can<br>
affect all Mac users that use ITK together with Qt (in 64-bit<br>
applications?).<br>
<br>
What happens is that in itkLightObject.h ITK defines a type named<br>
'InternalReferenceCountType' for the reference counting used by<br>
itkSmartPointer. On my Snow Leopard Mac it is using:<br>
<br>
#if [windows]<br>
#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)<br>
#if defined (__LP64__) && __LP64__<br>
typedef volatile int64_t InternalReferenceCountType;<br>
#else<br>
[32-bit version]<br>
#endif<br>
#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)<br>
typedef _Atomic_word InternalReferenceCountType;<br>
#else<br>
<br>
<br>
when building ITK itself, but unfortunately Qt forces<br>
MAC_OS_X_VERSION_MIN_REQUIRED to be 10.4 in their qglobal.h (ignoring<br>
any input of the user, although qmake actually has a<br>
QMAKE_MACOSX_DEPLOYMENT_TARGET variable to set the value, but this value<br>
is simply ignored):<br>
<br>
#ifdef Q_OS_DARWIN<br>
# ifdef MAC_OS_X_VERSION_MIN_REQUIRED<br>
# undef MAC_OS_X_VERSION_MIN_REQUIRED<br>
# endif<br>
# define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4<br>
...<br>
<br>
This means that when using ITK with Qt headers included first you end up with<br>
'_Atomic_word' instead of 'volatile int64_t', plus some additional<br>
confusion in itkLightObject.cxx.<br>
<br>
My guess now is that _Atomic_word is smaller in size then int64_t and on<br>
Snow Leopard (10.6) the trailing bits where usually 0 (unless when used<br>
MallocScribble, where it also crashed on this OS), while on Lion (where<br>
it almost always crashed) they were non-0, thus totally screwing up the<br>
reference counting.<br>
<br>
To cut a long story short, removing Qt's force override of the min<br>
required version from qglobal.h helped.<br>
<br>
Will file a Qt bug report now.<br>
<br>
Hope this helps other Mac/Qt/ITK users in the mean-time.<br>
<div class="HOEnZb"><div class="h5"><br>
Christian<br>
<br>
--<br>
Dr. Christian Lackas, Managing Partner<br>
inviCRO, LLC -- In Imaging Yours<br>
P: +1 617 933 8733, F: +49 2203 9034722, E: <a href="mailto:lackas@invicro.com">lackas@invicro.com</a><br>
<a href="http://www.invicro.com/" target="_blank">http://www.invicro.com/</a> <a href="http://www.spect-ct.com/" target="_blank">http://www.spect-ct.com/</a><br>
<br>
> * Sean McBride <<a href="mailto:sean@rogue-research.com">sean@rogue-research.com</a>> [111018 17:35]:<br>
><br>
> Hi Sean,<br>
><br>
> thanks once again.<br>
><br>
> > BTW, I recommend always using MallocScribble in Debug, it only affects<br>
> > performance minimally, and makes bugs repro much more easily.<br>
><br>
> yes, I like MallocScribble very much. Was not aware of it before, so<br>
> thanks again for the hint and I fully agree.<br>
><br>
> > >(gdb) p *m_Pointer<br>
> > >$2 = {<br>
> > > <itk::FiniteDifferenceFunction<itk::Image<float, 2u> >> = {<br>
> > > <itk::LightObject> = {<br>
> > > _vptr$LightObject = 0x5555555555555555,<br>
> > As the docs explain, when MallocScribble is set, all memory created<br>
> > with malloc/new is initialized to 0xAA and all freeed memory is set to<br>
> > 0x55. So _vptr$LightObject has been freed. Is the code you're<br>
> > running trying to use it after?<br>
><br>
> Yes, this is what causes the crash. The code is still within ITK,<br>
> though.<br>
><br>
> Reading more through the object factory code of ITK, I found<br>
> ObjectFactoryBase::CreateInstance(const char* itkclassname). This is<br>
> where the problem starts, since it returns 0 for my filter I want to<br>
> create. The itkclassname is<br>
><br>
> N3itk21CurvatureFlowFunctionINS_5ImageIfLj2EEEEE<br>
><br>
> It is somehow possible that this classname is not recognized by any<br>
> factory (e.g. since the signature is calculated slightly differently in<br>
> the factory and where I use it)?<br>
><br>
> ITK does not seem to handle the case that no factory handles a creation.<br>
> Is that supposed to be this way? Wondering if a warning before the<br>
> ultimate 'return 0;' at ObjectFactoryBase::CreateInstance(...) would be<br>
> of any use.<br>
><br>
> More important is of course the question why no factory believe it<br>
> should create my filter.<br>
><br>
> Christian<br>
><br>
> --<br>
> Dr. Christian Lackas, Managing Partner<br>
> inviCRO, LLC -- In Imaging Yours<br>
> P: +1 617 933 8733, F: +49 2203 9034722, E: <a href="mailto:lackas@invicro.com">lackas@invicro.com</a><br>
> <a href="http://www.invicro.com/" target="_blank">http://www.invicro.com/</a> <a href="http://www.spect-ct.com/" target="_blank">http://www.spect-ct.com/</a><br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>------------------------------------------------------------------<br>Simon Esneault<div>13 rue Vasselot<br>35000 Rennes, France<br>Tel : 06 64 61 30 94<br>
Mail : <a href="mailto:simon.esneault@gmail.com" target="_blank">simon.esneault@gmail.com</a><br>------------------------------------------------------------------</div><br>
</div></div>