Thanks for pointing out the bug. Its fairly basic. I don't believe the factory method of dynamically loading objects from shared libs could've ever worked with that bug. This has been fixed now.. <br><br><a href="http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkMacro.h?root=Insight&amp;r1=1.68&amp;r2=1.69">
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkMacro.h?root=Insight&amp;r1=1.68&amp;r2=1.69</a><br><br>[Needless to say, anybody updating ITK will spend a few hours re-compiling :) ].<br><br>bye<br>-karthik<br>
<br><div><span class="gmail_quote">On 11/13/06, <b class="gmail_sendername">Marco Nolden</b> &lt;<a href="mailto:m.nolden@dkfz-heidelberg.de">m.nolden@dkfz-heidelberg.de</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br><br>I want to use the itk factory mechanism to replace the implementation of<br>one of the classes in our framework MITK. The class is called<br>mitk::Plugin (inherits itk::Object) and I want to replace it with
<br>mitk::SomePluginImpl if it is available. In my factory class I call<br><br>this-&gt;RegisterOverride(typeid(mitk::Plugin).name(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeid(mitk::SomePluginImpl).name(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;MITK Some Plugin&quot;,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itk::CreateObjectFunction&lt;mitk::SomePluginImpl&gt;::New());<br><br><br>and register it with<br><br>itk::ObjectFactoryBase::RegisterFactory(this);<br><br>If I call now<br><br>&nbsp;&nbsp;mitk::Plugin::Pointer = mitk::Plugin::New();
<br><br>it crashes, since in the itkNewMacro of the superclass (mitk::Plugin)<br>the smart pointer to the correctly instantiated mitk::SomePluginImpl<br>instance generated by the factory is assigned to a raw ptr and thus the
<br>reference count is decreased to zero and the object deleted:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 335 #define itkNewMacro(x) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 336 static Pointer New(void) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 337 { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 338&nbsp;&nbsp; Pointer smartPtr; \<br>crash&gt;&gt;&gt;&gt;339&nbsp;&nbsp; x *rawPtr = ::itk::ObjectFactory&lt;x&gt;::Create(); \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 340&nbsp;&nbsp; if(rawPtr == NULL) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 341&nbsp;&nbsp;&nbsp;&nbsp; { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 342&nbsp;&nbsp;&nbsp;&nbsp; rawPtr = new x; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 343&nbsp;&nbsp;&nbsp;&nbsp; } \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 344&nbsp;&nbsp; smartPtr = rawPtr; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 345&nbsp;&nbsp; rawPtr-&gt;UnRegister(); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 346&nbsp;&nbsp; return smartPtr; \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 347 } \<br><br><br>For now I have created a workaround by writing my own<br>CreateObjectFunction which just calls an extra Register() on the<br>generated object.<br><br>Am I getting something wrong about how the factory works? And why is it
<br>not possible in the itkNewMacro to assign the new pointer (no matter<br>whether created by c++ 'new' or the factory) directly to smartPtr<br>instead of rawPtr. This would also fix the problem I described.<br><br>I hope someone on the list can help me to understand these issues.
<br><br>Regards<br><br>Marco<br><br><br><br><br><br><br>--<br>----------------------------------------------------------------------<br>Dipl.-Inform. Med. Marco Nolden<br>Deutsches Krebsforschungszentrum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (German Cancer Research Center)
<br>Div. Medical &amp; Biological Informatics&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tel: (+49) 6221-42 2325<br>Im Neuenheimer Feld 280&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fax: (+49) 6221-42 2345<br>D-69120 Heidelberg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eMail: <a href="mailto:M.Nolden@dkfz.de">
M.Nolden@dkfz.de</a><br>_______________________________________________<br>Insight-users mailing list<br><a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users">
http://www.itk.org/mailman/listinfo/insight-users</a><br></blockquote></div><br><br clear="all"><br>