From 6168454ebeb518ebf3589c8a5cff91aca70f23e5 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Thu, 22 Feb 2018 17:44:16 +0100
Subject: [PATCH] BUG: beware of nullptr

---
 .../src/otbWrapperApplication.cxx             | 32 ++++++++-----------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
index 69df972b30..e93134628a 100644
--- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
+++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
@@ -363,6 +363,7 @@ void Application::AfterExecuteAndWriteOutputs()
 void
 Application::RegisterPipeline()
 {
+  std::cout<<"Registering Pipeline"<<std::endl;
   m_Filters.clear();
   std::stack< itk::DataObject * > dataStack;
   std::set< itk::DataObject * > inputData;
@@ -377,23 +378,26 @@ Application::RegisterPipeline()
       Parameter* param = GetParameterByKey(key);
       OutputImageParameter * outP = dynamic_cast<OutputImageParameter*>(param);
       itk::ImageBase<2> * outData = outP->GetValue();
-      std::cout<<"one image in output"<<std::endl;
-      dataStack.push(outData);
+      if ( outData )
+        dataStack.push(outData);
       }
     else if ( GetParameterType(key) == ParameterType_OutputVectorData )
       {
       Parameter* param = GetParameterByKey(key);
       OutputVectorDataParameter * outP = dynamic_cast<OutputVectorDataParameter*>(param);
       Wrapper::VectorDataType * outData = outP->GetValue();
-      dataStack.push(outData);
+      if ( outData )
+        dataStack.push(outData);
       }
     else if ( GetParameterType(key) == ParameterType_InputImage )
       {
       Parameter* param = GetParameterByKey(key);
       InputImageParameter * inP = dynamic_cast<InputImageParameter*>(param);
       itk::ImageBase<2> * inData = inP->GetPointer();
-      inputData.insert(inData);
+      if ( inData )
+        inputData.insert(inData);
       }
+      // need to take care of list object
     }
   // DFS
   std::set< itk::ProcessObject * > processSet;
@@ -402,35 +406,27 @@ Application::RegisterPipeline()
     std::cout<<"one data  is processed"<<std::endl;
     itk::DataObject * current = dataStack.top();
     dataStack.pop();
-    if ( inputData.find( current ) != inputData.end() )
+    if ( inputData.count( current ) || !current )
       continue;
     std::cout<<"not an input"<<std::endl;
-    if ( dynamic_cast<itk::ImageBase<2> * > ( current ) )
-      {
-      itk::ImageBase<2> * image = dynamic_cast<itk::ImageBase<2> * > ( current );
-      itk::ImageBase<2>::SizeType sizenull;
-      sizenull.Fill(0);
-      if ( image->GetLargestPossibleRegion() == image->GetBufferedRegion() && image->GetBufferedRegion().GetSize() != sizenull )
-        continue;
-      }
-    std::cout<<"not empty"<<std::endl;
     itk::ProcessObject * process = (current->GetSource()).GetPointer();
-    if ( processSet.find( process ) != processSet.end())
+    if ( processSet.find( process ) != processSet.end() || !process )
       continue;
     std::cout<<"add process to set"<<std::endl;
     processSet.insert( process );
     std::vector< itk::DataObject::Pointer > inputs = process->GetInputs();
     for ( auto it : inputs )
       {
-      if ( inputData.find(it.GetPointer()) != inputData.end() )
+      if ( inputData.count( it.GetPointer() ) )
         continue;
       dataStack.push( it.GetPointer() );
       }
     }
-
+  // Convert the set into a vector 
+  // Might not need it
   for ( auto it : processSet )
   {
-    std::cout<<"one filter is registered"<<std::endl;
+    std::cout<<"one filter is registered : "<<it->GetNameOfClass()<<std::endl;
     m_Filters.push_back( it );
   }
 }
-- 
GitLab