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&r1=1.68&r2=1.69">
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkMacro.h?root=Insight&r1=1.68&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> <<a href="mailto:m.nolden@dkfz-heidelberg.de">m.nolden@dkfz-heidelberg.de</a>> 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->RegisterOverride(typeid(mitk::Plugin).name(),<br> typeid(mitk::SomePluginImpl).name(),<br> "MITK Some Plugin",
<br> 1,<br> itk::CreateObjectFunction<mitk::SomePluginImpl>::New());<br><br><br>and register it with<br><br>itk::ObjectFactoryBase::RegisterFactory(this);<br><br>If I call now<br><br> 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> 335 #define itkNewMacro(x) \<br> 336 static Pointer New(void) \<br> 337 { \<br> 338 Pointer smartPtr; \<br>crash>>>>339 x *rawPtr = ::itk::ObjectFactory<x>::Create(); \
<br> 340 if(rawPtr == NULL) \<br> 341 { \<br> 342 rawPtr = new x; \<br> 343 } \<br> 344 smartPtr = rawPtr; \<br> 345 rawPtr->UnRegister(); \<br> 346 return smartPtr; \
<br> 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 (German Cancer Research Center)
<br>Div. Medical & Biological Informatics Tel: (+49) 6221-42 2325<br>Im Neuenheimer Feld 280 Fax: (+49) 6221-42 2345<br>D-69120 Heidelberg 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>