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">&lt;<a href="mailto:lackas@invicro.com">lackas@invicro.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">* Christian Lackas &lt;<a href="mailto:lackas@invicro.com">lackas@invicro.com</a>&gt; [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 &#39;new&#39;).<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>
&#39;InternalReferenceCountType&#39; for the reference counting used by<br>
itkSmartPointer. On my Snow Leopard Mac it is using:<br>
<br>
    #if [windows]<br>
    #elif defined(__APPLE__) &amp;&amp; (MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 1050)<br>
     #if defined (__LP64__) &amp;&amp; __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>
&#39;_Atomic_word&#39; instead of &#39;volatile int64_t&#39;, 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&#39;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>
&gt; * Sean McBride &lt;<a href="mailto:sean@rogue-research.com">sean@rogue-research.com</a>&gt; [111018 17:35]:<br>
&gt;<br>
&gt; Hi Sean,<br>
&gt;<br>
&gt; thanks once again.<br>
&gt;<br>
&gt; &gt; BTW, I recommend always using MallocScribble in Debug, it only affects<br>
&gt; &gt; performance minimally, and makes bugs repro much more easily.<br>
&gt;<br>
&gt; yes, I like MallocScribble very much. Was not aware of it before, so<br>
&gt; thanks again for the hint and I fully agree.<br>
&gt;<br>
&gt; &gt; &gt;(gdb) p *m_Pointer<br>
&gt; &gt; &gt;$2 = {<br>
&gt; &gt; &gt;  &lt;itk::FiniteDifferenceFunction&lt;itk::Image&lt;float, 2u&gt; &gt;&gt; = {<br>
&gt; &gt; &gt;    &lt;itk::LightObject&gt; = {<br>
&gt; &gt; &gt;      _vptr$LightObject = 0x5555555555555555,<br>
&gt; &gt; As the docs explain, when MallocScribble is set, all memory created<br>
&gt; &gt; with malloc/new is initialized to 0xAA and all freeed memory is set to<br>
&gt; &gt; 0x55.  So _vptr$LightObject has been freed.  Is the code you&#39;re<br>
&gt; &gt; running trying to use it after?<br>
&gt;<br>
&gt; Yes, this is what causes the crash. The code is still within ITK,<br>
&gt; though.<br>
&gt;<br>
&gt; Reading more through the object factory code of ITK, I found<br>
&gt; ObjectFactoryBase::CreateInstance(const char* itkclassname). This is<br>
&gt; where the problem starts, since it returns 0 for my filter I want to<br>
&gt; create. The itkclassname is<br>
&gt;<br>
&gt;     N3itk21CurvatureFlowFunctionINS_5ImageIfLj2EEEEE<br>
&gt;<br>
&gt; It is somehow possible that this classname is not recognized by any<br>
&gt; factory (e.g. since the signature is calculated slightly differently in<br>
&gt; the factory and where I use it)?<br>
&gt;<br>
&gt; ITK does not seem to handle the case that no factory handles a creation.<br>
&gt; Is that supposed to be this way? Wondering if a warning before the<br>
&gt; ultimate &#39;return 0;&#39; at ObjectFactoryBase::CreateInstance(...) would be<br>
&gt; of any use.<br>
&gt;<br>
&gt; More important is of course the question why no factory believe it<br>
&gt; should create my filter.<br>
&gt;<br>
&gt; Christian<br>
&gt;<br>
&gt; --<br>
&gt; Dr. Christian Lackas, Managing Partner<br>
&gt; inviCRO, LLC -- In Imaging Yours<br>
&gt; P: +1 617 933 8733, F: +49 2203 9034722, E: <a href="mailto:lackas@invicro.com">lackas@invicro.com</a><br>
&gt; <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>